removing mdm archtype

This commit is contained in:
ayyoob 2016-05-17 21:15:48 +05:30
parent 0a2860d0d4
commit 9e8181c226
180 changed files with 0 additions and 12692 deletions

View File

@ -1,18 +0,0 @@
Prerequisites
1. Apache maven 3.1.1 or higher & M2_HOME environment variable must be set
2. Apache Ant 1.9.3 or higher
3. Android SDK (SDK 17 or higher) must be installed & ANDROID_HOME environment variable must be set
4. Android sdk (V 5.0) jars must be published to local repo using [1].
How to use Generate a MDM-Android-agent project
1. Generate the mdm-android-agent project by executing android-agent.sh shell-script.
2. Provide the client-Key & client-Secret & target Android SDK version in the interactive mode.
3. Then the script will install the maven archetype to the local repository, generate a mdm-android-agent project with provided arguments and build the apk.
[1]. https://github.com/simpligility/maven-android-sdk-deployer

View File

@ -1,87 +0,0 @@
#!/bin/sh
#
# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. licenses this file to you 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.
#
#
# Script to generate WSO2 MDM Android agent
#
clear
echo "Please provide the ClientKey: "
read clientKey
echo "Please provide the ClientSecret: "
read clientSecret
# Default Target Android SDK version
DEFAULT_TARGET_SDK="21"
echo "************** Prerequisites verification started **************"
echo "Verifying the Apache Maven installation"
if [ -d "$M2_HOME" ];then
echo $M2_HOME
else
echo "Apache Maven is not installed in the system. Please install Apache Maven 3.1.1 or higher and set M2_HOME environment variable."
exit -1
fi
echo "Verifying the Android SDK installation"
if [ -d "$ANDROID_HOME" ];then
echo $ANDROID_HOME
else
echo "Android SDK is not installed in the system. Please install the Android SDK and set ANDROID_HOME environment variable."
exit -1
fi
echo "************** Prerequisites verification completed **************"
echo "************** Verifying the arguments **************"
if [ -n "$clientKey" ];then
echo "Setting the clientKey to $clientKey"
else
echo "Client-Key is not defined."
exit 1;
fi
if [ -n "$clientSecret" ];then
echo "Setting the clientSecret to $clientSecret"
else
echo "Client-Secret is not defined."
exit 1;
fi
echo "************** Argument verification completed **************"
echo "************** Installing WSO2 MDM Android Agent Archetype to the maven repo **************"
mvn install:install-file -Dfile=mdm-android-agent-archetype-1.0.0-SNAPSHOT.jar -DgroupId=org.wso2.mdmr -DartifactId=mdm-android-agent-archetype -Dversion=1.0.0-SNAPSHOT -Dpackaging=jar -DgeneratePom=true
echo "************** Generating WSO2 MDM Android agent project ***************"
mvn archetype:generate -B -DarchetypeGroupId=org.wso2.mdm -DarchetypeArtifactId=mdm-android-agent-archetype -DarchetypeVersion=1.0.0-SNAPSHOT -DgroupId=org.wso2.mdm -DartifactId=mdm-android-client -DclientKey=$clientKey -DclientSecret=$clientSecret
echo "************** Adding IDPProxy to maven repo ***************"
mvn -f mdm-android-client/src/main/plugins/IDPProxy/pom.xml clean install
echo "************** Building MDM Android Agent ***************"
mvn -f mdm-android-client/pom.xml clean install
exit 0

View File

@ -1,70 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.wso2.iot</groupId>
<artifactId>wso2cdmf-tools</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mdm-android-agent-archetype</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>WSO2 MDM Agent Android Archetype</name>
<description>Creates a MDM-Android agent project</description>
<packaging>maven-archetype</packaging>
<organization>
<name>WSO2 Inc.</name>
<url>http://www.wso2.com</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>${archetype.packaging.version}</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>${archetype.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<archetype.packaging.version>2.2</archetype.packaging.version>
<archetype.plugin.version>2.2</archetype.plugin.version>
</properties>
</project>

View File

@ -1,82 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<archetype-descriptor name="mdm-android-agent">
<requiredProperties>
<requiredProperty key="platform">
<defaultValue>21</defaultValue>
</requiredProperty>
<requiredProperty key="clientKey">
<defaultValue>client-key</defaultValue>
</requiredProperty>
<requiredProperty key="clientSecret">
<defaultValue>client-secret</defaultValue>
</requiredProperty>
</requiredProperties>
<fileSets>
<fileSet filtered="false" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="false" encoding="UTF-8">
<directory>src/main/assets</directory>
<includes>
<include>*.properties</include>
</includes>
</fileSet>
<fileSet filtered="false" encoding="UTF-8">
<directory>src/main/plugins</directory>
<includes>
<include>**/*.*</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/res</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet filtered="false" encoding="UTF-8">
<directory>src/main/res</directory>
<includes>
<include>**/*.png</include>
</includes>
</fileSet>
<fileSet filtered="false" encoding="UTF-8">
<directory>src/main</directory>
<includes>
<include>*.properties</include>
</includes>
</fileSet>
<fileSet filtered="false" encoding="UTF-8">
<directory>src/main</directory>
<includes>
<include>*.txt</include>
</includes>
</fileSet>
<fileSet filtered="false" encoding="UTF-8">
<directory>src/main</directory>
<includes>
<include>*.xml</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>

View File

@ -1,193 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.mdm</groupId>
<artifactId>mdm-android-client</artifactId>
<version>1.0.0</version>
<packaging>apk</packaging>
<name>MDM-Android-Client-App</name>
<dependencies>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>${android.lib.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>${actionbarsherlock.version}</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android.gcm</groupId>
<artifactId>gcm-client</artifactId>
<version>${gcm.client.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>${json.simple.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons.codec.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>idp-proxy</artifactId>
<version>${idp.proxy.version}</version>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${it-plugin.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>${android.sdk.version}</platform>
</sdk>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<it-plugin.version>4.0.0</it-plugin.version>
<compiler-plugin.version>3.1</compiler-plugin.version>
<android.sdk.version>21</android.sdk.version>
<android.lib.version>5.0.1_r2</android.lib.version>
<actionbarsherlock.version>4.2.0</actionbarsherlock.version>
<gcm.client.version>1.0.2</gcm.client.version>
<json.simple.version>1.1</json.simple.version>
<commons.codec.version>1.9</commons.codec.version>
<idp.proxy.version>1.0.0</idp.proxy.version>
</properties>
<pluginRepositories>
<pluginRepository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</pluginRepository>
<pluginRepository>
<id>wso2.snapshots</id>
<name>Apache Snapshot Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
<repository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
<repository>
<id>wso2.snapshots</id>
<name>WSO2 Snapshot Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>gcm-server-repository</id>
<url>https://raw.githubusercontent.com/slorber/gcm-server-repository/master/releases/
</url>
</repository>
</repositories>
</project>

View File

@ -1,171 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.wso2.mdm.agent"
android:sharedUserId="org.wso2.mdm.agent"
android:sharedUserLabel="@string/hello_world"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<permission
android:name="org.wso2.mdm.agent.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="org.wso2.mdm.agent.permission.C2D_MESSAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE">
</uses-permission>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permisssion.ACCESS_COARSE_LOCATION">
</uses-permission>
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS">
</uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
</uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/TopBarTheme">
<activity
android:name="org.wso2.mdm.agent.RegistrationActivity"
android:screenOrientation="portrait"
android:theme="@style/TopBarTheme">
</activity>
<activity
android:name="org.wso2.mdm.agent.DisplayDeviceInfoActivity"
android:label="@string/title_activity_display_device_info"
android:screenOrientation="portrait">
</activity>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="org.wso2.mdm.agent"/>
</intent-filter>
</receiver>
<receiver
android:name="org.wso2.mdm.agent.services.AgentDeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<intent-filter>
<!-- This action is required -->
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
</intent-filter>
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/agent_device_admin">
</meta-data>
</receiver>
<receiver android:name="org.wso2.mdm.agent.services.SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
<receiver android:name="org.wso2.mdm.agent.services.AlarmReceiver"/>
<receiver
android:name="org.wso2.mdm.agent.services.DeviceStartupIntentReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<service android:name="org.wso2.mdm.agent.GCMIntentService"/>
<activity
android:name="org.wso2.mdm.agent.AlreadyRegisteredActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock">
</activity>
<activity
android:name="org.wso2.mdm.agent.AuthenticationActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock"
android:windowSoftInputMode="stateUnchanged|adjustPan">
</activity>
<activity
android:name="org.wso2.mdm.agent.AuthenticationErrorActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.wso2.mdm.agent.NotifyActivity"
android:label="@string/title_activity_notify"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.wso2.mdm.agent.ServerDetails"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateUnchanged|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="org.wso2.mdm.agent.PinCodeActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateUnchanged|adjustPan">
</activity>
<activity
android:name="org.wso2.mdm.agent.Notification"
android:label="@string/title_activity_notification"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.wso2.mdm.agent.AlertActivity"
android:label="@string/title_activity_alert"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Dialog">
</activity>
</application>
</manifest>

View File

@ -1,18 +0,0 @@
WSO2 EMM Agent
=================
Configure and build the Android client application
----------------------
Follow the instructions below to configure and build the Android client application:
1. Get a Git clone of the project.
2. Download <a href="https://developer.android.com/sdk/installing/installing-adt.html"> Android ADT plugin and configure </a> it in your Eclipse.
3. Open the project in your Eclipse IDE.
4. Import the project as an Android project using "File-->Import-->Existing Android Code Into Workspace"
5. Two projects will show, a library and the agent. Clean the Library first and build it.
6. Open the file properties of the Agent project.
7. Under "Android" scroll down (past the Build targets).
8. The library project will show with a red "X" next to it. Remove it.
9. Add the library project you just built in step 3
10. Ensure the Library is also on your "Java Build Path" under Libraries.
11. Clean and build.

View File

@ -1,19 +0,0 @@
#
# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. licenses this file to you 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.
#
SHOP_URL=""

View File

@ -1,202 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.wso2.cdm.agent"
android:sharedUserId="org.wso2.cdm.agent"
android:sharedUserLabel="@string/hello_world"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17"/>
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!--
Creates a custom permission so only this app can receive its messages.
NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
where PACKAGE is the application's package name.
-->
<permission
android:name="org.wso2.emm.agent.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="org.wso2.emm.agent.permission.C2D_MESSAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE">
</uses-permission>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permisssion.ACCESS_COARSE_LOCATION">
</uses-permission>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS">
</uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
</uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/TopBarTheme">
<activity
android:name="org.wso2.cdm.agent.RegistrationActivity"
android:screenOrientation="portrait"
android:theme="@style/TopBarTheme">
</activity>
<activity
android:name="org.wso2.cdm.agent.DisplayDeviceInfoActivity"
android:label="@string/title_activity_display_device_info"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.wso2.cdm.agent.RegisterSuccessfulActivity"
android:label="@string/title_activity_register_successful"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock">
</activity>
<!-- Begin List of Receivers -->
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="org.wso2.emm.agent"/>
</intent-filter>
</receiver>
<receiver
android:name="org.wso2.cdm.agent.services.WSO2DeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<intent-filter>
<!-- This action is required -->
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
</intent-filter>
<!-- This is required this receiver to become device admin component. -->
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/wso2_device_admin">
</meta-data>
</receiver>
<receiver android:name="org.wso2.cdm.agent.services.SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
<receiver android:name="org.wso2.cdm.agent.services.AlarmReceiver"></receiver>
<receiver android:name="org.wso2.cdm.agent.services.DeviceStartupIntentReceiver"
android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<!-- End List of Receivers -->
<service android:name="org.wso2.cdm.agent.GCMIntentService"/>
<activity
android:name="org.wso2.cdm.agent.AlreadyRegisteredActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock">
</activity>
<activity
android:name="org.wso2.cdm.agent.AuthenticationActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock"
android:windowSoftInputMode="stateUnchanged|adjustPan">
</activity>
<activity
android:name="org.wso2.cdm.agent.AuthenticationErrorActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.wso2.cdm.agent.NotifyActivity"
android:label="@string/title_activity_notify"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.wso2.cdm.agent.ServerDetails"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:windowSoftInputMode="stateUnchanged|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="org.wso2.cdm.agent.PinCodeActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateUnchanged|adjustPan">
</activity>
<activity
android:name="org.wso2.cdm.agent.Notification"
android:label="@string/title_activity_notification"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.wso2.cdm.agent.AlertActivity"
android:label="@string/title_activity_alert"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Dialog">
</activity>
<activity
android:name="org.wso2.cdm.agent.LogActivity"
android:label="@string/title_activity_log"
android:screenOrientation="portrait">
</activity>
</application>
</manifest>

View File

@ -1,911 +0,0 @@
int attr actionBarDivider 0x7f01000e
int attr actionBarItemBackground 0x7f01000f
int attr actionBarSize 0x7f01000d
int attr actionBarSplitStyle 0x7f01000b
int attr actionBarStyle 0x7f01000a
int attr actionBarTabBarStyle 0x7f010007
int attr actionBarTabStyle 0x7f010006
int attr actionBarTabTextStyle 0x7f010008
int attr actionBarWidgetTheme 0x7f01000c
int attr actionButtonStyle 0x7f01003a
int attr actionDropDownStyle 0x7f010039
int attr actionMenuTextAppearance 0x7f010010
int attr actionMenuTextColor 0x7f010011
int attr actionModeBackground 0x7f010014
int attr actionModeCloseButtonStyle 0x7f010013
int attr actionModeCloseDrawable 0x7f010016
int attr actionModePopupWindowStyle 0x7f010018
int attr actionModeShareDrawable 0x7f010017
int attr actionModeSplitBackground 0x7f010015
int attr actionModeStyle 0x7f010012
int attr actionOverflowButtonStyle 0x7f010009
int attr actionSpinnerItemStyle 0x7f01003f
int attr activatedBackgroundIndicator 0x7f010047
int attr activityChooserViewStyle 0x7f010046
int attr background 0x7f010002
int attr backgroundSplit 0x7f010003
int attr backgroundStacked 0x7f01004e
int attr buttonStyleSmall 0x7f010019
int attr customNavigationLayout 0x7f01004f
int attr displayOptions 0x7f010049
int attr divider 0x7f010005
int attr dividerVertical 0x7f010038
int attr dropDownListViewStyle 0x7f01003c
int attr dropdownListPreferredItemHeight 0x7f01003e
int attr expandActivityOverflowButtonDrawable 0x7f01005e
int attr headerBackground 0x7f010058
int attr height 0x7f010004
int attr homeAsUpIndicator 0x7f01003b
int attr homeLayout 0x7f010050
int attr horizontalDivider 0x7f010056
int attr icon 0x7f01004c
int attr iconifiedByDefault 0x7f01005f
int attr indeterminateProgressStyle 0x7f010052
int attr initialActivityCount 0x7f01005d
int attr itemBackground 0x7f010059
int attr itemIconDisabledAlpha 0x7f01005b
int attr itemPadding 0x7f010054
int attr itemTextAppearance 0x7f010055
int attr listPopupWindowStyle 0x7f010045
int attr listPreferredItemHeightSmall 0x7f010032
int attr listPreferredItemPaddingLeft 0x7f010033
int attr listPreferredItemPaddingRight 0x7f010034
int attr logo 0x7f01004d
int attr navigationMode 0x7f010048
int attr popupMenuStyle 0x7f01003d
int attr preserveIconSpacing 0x7f01005c
int attr progressBarPadding 0x7f010053
int attr progressBarStyle 0x7f010051
int attr queryHint 0x7f010060
int attr searchAutoCompleteTextView 0x7f010024
int attr searchDropdownBackground 0x7f010025
int attr searchResultListItemHeight 0x7f01002f
int attr searchViewCloseIcon 0x7f010026
int attr searchViewEditQuery 0x7f01002a
int attr searchViewEditQueryBackground 0x7f01002b
int attr searchViewGoIcon 0x7f010027
int attr searchViewSearchIcon 0x7f010028
int attr searchViewTextField 0x7f01002c
int attr searchViewTextFieldRight 0x7f01002d
int attr searchViewVoiceIcon 0x7f010029
int attr selectableItemBackground 0x7f01001a
int attr spinnerDropDownItemStyle 0x7f010023
int attr spinnerItemStyle 0x7f010022
int attr subtitle 0x7f01004b
int attr subtitleTextStyle 0x7f010001
int attr textAppearanceLargePopupMenu 0x7f01001c
int attr textAppearanceListItemSmall 0x7f010035
int attr textAppearanceSearchResultSubtitle 0x7f010031
int attr textAppearanceSearchResultTitle 0x7f010030
int attr textAppearanceSmall 0x7f01001e
int attr textAppearanceSmallPopupMenu 0x7f01001d
int attr textColorPrimary 0x7f01001f
int attr textColorPrimaryDisableOnly 0x7f010020
int attr textColorPrimaryInverse 0x7f010021
int attr textColorSearchUrl 0x7f01002e
int attr title 0x7f01004a
int attr titleTextStyle 0x7f010000
int attr verticalDivider 0x7f010057
int attr windowActionBar 0x7f010041
int attr windowActionBarOverlay 0x7f010042
int attr windowActionModeOverlay 0x7f010043
int attr windowAnimationStyle 0x7f01005a
int attr windowContentOverlay 0x7f01001b
int attr windowMinWidthMajor 0x7f010036
int attr windowMinWidthMinor 0x7f010037
int attr windowNoTitle 0x7f010040
int attr windowSplitActionBar 0x7f010044
int bool abs__action_bar_embed_tabs 0x7f070000
int bool abs__action_bar_expanded_action_views_exclusive 0x7f070002
int bool abs__config_actionMenuItemAllCaps 0x7f070004
int bool abs__config_allowActionMenuItemTextWithIcon 0x7f070005
int bool abs__config_showMenuShortcutsWhenKeyboardPresent 0x7f070003
int bool abs__split_action_bar_is_narrow 0x7f070001
int color abs__background_holo_dark 0x7f080000
int color abs__background_holo_light 0x7f080001
int color abs__bright_foreground_disabled_holo_dark 0x7f080004
int color abs__bright_foreground_disabled_holo_light 0x7f080005
int color abs__bright_foreground_holo_dark 0x7f080002
int color abs__bright_foreground_holo_light 0x7f080003
int color abs__bright_foreground_inverse_holo_dark 0x7f080006
int color abs__bright_foreground_inverse_holo_light 0x7f080007
int color abs__holo_blue_light 0x7f080008
int color abs__primary_text_disable_only_holo_dark 0x7f08000c
int color abs__primary_text_disable_only_holo_light 0x7f08000d
int color abs__primary_text_holo_dark 0x7f08000e
int color abs__primary_text_holo_light 0x7f08000f
int color black 0x7f08000b
int color light_grey 0x7f080009
int color white 0x7f08000a
int dimen abs__action_bar_default_height 0x7f090001
int dimen abs__action_bar_icon_vertical_padding 0x7f090002
int dimen abs__action_bar_subtitle_bottom_margin 0x7f090006
int dimen abs__action_bar_subtitle_text_size 0x7f090004
int dimen abs__action_bar_subtitle_top_margin 0x7f090005
int dimen abs__action_bar_title_text_size 0x7f090003
int dimen abs__action_button_min_width 0x7f090007
int dimen abs__alert_dialog_title_height 0x7f090008
int dimen abs__config_prefDialogWidth 0x7f090000
int dimen abs__dialog_min_width_major 0x7f090009
int dimen abs__dialog_min_width_minor 0x7f09000a
int dimen abs__dropdownitem_icon_width 0x7f09000d
int dimen abs__dropdownitem_text_padding_left 0x7f09000b
int dimen abs__dropdownitem_text_padding_right 0x7f09000c
int dimen abs__search_view_preferred_width 0x7f09000f
int dimen abs__search_view_text_min_width 0x7f09000e
int dimen action_button_min_width 0x7f090010
int dimen activity_horizontal_margin 0x7f090011
int dimen activity_vertical_margin 0x7f090012
int dimen top_bar_height 0x7f090013
int drawable abs__ab_bottom_solid_dark_holo 0x7f020000
int drawable abs__ab_bottom_solid_inverse_holo 0x7f020001
int drawable abs__ab_bottom_solid_light_holo 0x7f020002
int drawable abs__ab_bottom_transparent_dark_holo 0x7f020003
int drawable abs__ab_bottom_transparent_light_holo 0x7f020004
int drawable abs__ab_share_pack_holo_dark 0x7f020005
int drawable abs__ab_share_pack_holo_light 0x7f020006
int drawable abs__ab_solid_dark_holo 0x7f020007
int drawable abs__ab_solid_light_holo 0x7f020008
int drawable abs__ab_solid_shadow_holo 0x7f020009
int drawable abs__ab_stacked_solid_dark_holo 0x7f02000a
int drawable abs__ab_stacked_solid_light_holo 0x7f02000b
int drawable abs__ab_stacked_transparent_dark_holo 0x7f02000c
int drawable abs__ab_stacked_transparent_light_holo 0x7f02000d
int drawable abs__ab_transparent_dark_holo 0x7f02000e
int drawable abs__ab_transparent_light_holo 0x7f02000f
int drawable abs__activated_background_holo_dark 0x7f020010
int drawable abs__activated_background_holo_light 0x7f020011
int drawable abs__btn_cab_done_default_holo_dark 0x7f020012
int drawable abs__btn_cab_done_default_holo_light 0x7f020013
int drawable abs__btn_cab_done_focused_holo_dark 0x7f020014
int drawable abs__btn_cab_done_focused_holo_light 0x7f020015
int drawable abs__btn_cab_done_holo_dark 0x7f020016
int drawable abs__btn_cab_done_holo_light 0x7f020017
int drawable abs__btn_cab_done_pressed_holo_dark 0x7f020018
int drawable abs__btn_cab_done_pressed_holo_light 0x7f020019
int drawable abs__cab_background_bottom_holo_dark 0x7f02001a
int drawable abs__cab_background_bottom_holo_light 0x7f02001b
int drawable abs__cab_background_top_holo_dark 0x7f02001c
int drawable abs__cab_background_top_holo_light 0x7f02001d
int drawable abs__dialog_full_holo_dark 0x7f02001e
int drawable abs__dialog_full_holo_light 0x7f02001f
int drawable abs__ic_ab_back_holo_dark 0x7f020020
int drawable abs__ic_ab_back_holo_light 0x7f020021
int drawable abs__ic_cab_done_holo_dark 0x7f020022
int drawable abs__ic_cab_done_holo_light 0x7f020023
int drawable abs__ic_clear 0x7f020024
int drawable abs__ic_clear_disabled 0x7f020025
int drawable abs__ic_clear_holo_light 0x7f020026
int drawable abs__ic_clear_normal 0x7f020027
int drawable abs__ic_clear_search_api_disabled_holo_light 0x7f020028
int drawable abs__ic_clear_search_api_holo_light 0x7f020029
int drawable abs__ic_go 0x7f02002a
int drawable abs__ic_go_search_api_holo_light 0x7f02002b
int drawable abs__ic_menu_moreoverflow_holo_dark 0x7f02002c
int drawable abs__ic_menu_moreoverflow_holo_light 0x7f02002d
int drawable abs__ic_menu_moreoverflow_normal_holo_dark 0x7f02002e
int drawable abs__ic_menu_moreoverflow_normal_holo_light 0x7f02002f
int drawable abs__ic_menu_share_holo_dark 0x7f020030
int drawable abs__ic_menu_share_holo_light 0x7f020031
int drawable abs__ic_search 0x7f020032
int drawable abs__ic_search_api_holo_light 0x7f020033
int drawable abs__ic_voice_search 0x7f020034
int drawable abs__ic_voice_search_api_holo_light 0x7f020035
int drawable abs__item_background_holo_dark 0x7f020036
int drawable abs__item_background_holo_light 0x7f020037
int drawable abs__list_activated_holo 0x7f020038
int drawable abs__list_divider_holo_dark 0x7f020039
int drawable abs__list_divider_holo_light 0x7f02003a
int drawable abs__list_focused_holo 0x7f02003b
int drawable abs__list_longpressed_holo 0x7f02003c
int drawable abs__list_pressed_holo_dark 0x7f02003d
int drawable abs__list_pressed_holo_light 0x7f02003e
int drawable abs__list_selector_background_transition_holo_dark 0x7f02003f
int drawable abs__list_selector_background_transition_holo_light 0x7f020040
int drawable abs__list_selector_disabled_holo_dark 0x7f020041
int drawable abs__list_selector_disabled_holo_light 0x7f020042
int drawable abs__list_selector_holo_dark 0x7f020043
int drawable abs__list_selector_holo_light 0x7f020044
int drawable abs__menu_dropdown_panel_holo_dark 0x7f020045
int drawable abs__menu_dropdown_panel_holo_light 0x7f020046
int drawable abs__progress_bg_holo_dark 0x7f020047
int drawable abs__progress_bg_holo_light 0x7f020048
int drawable abs__progress_horizontal_holo_dark 0x7f020049
int drawable abs__progress_horizontal_holo_light 0x7f02004a
int drawable abs__progress_medium_holo 0x7f02004b
int drawable abs__progress_primary_holo_dark 0x7f02004c
int drawable abs__progress_primary_holo_light 0x7f02004d
int drawable abs__progress_secondary_holo_dark 0x7f02004e
int drawable abs__progress_secondary_holo_light 0x7f02004f
int drawable abs__search_dropdown_dark 0x7f020050
int drawable abs__search_dropdown_light 0x7f020051
int drawable abs__spinner_48_inner_holo 0x7f020052
int drawable abs__spinner_48_outer_holo 0x7f020053
int drawable abs__spinner_ab_default_holo_dark 0x7f020054
int drawable abs__spinner_ab_default_holo_light 0x7f020055
int drawable abs__spinner_ab_disabled_holo_dark 0x7f020056
int drawable abs__spinner_ab_disabled_holo_light 0x7f020057
int drawable abs__spinner_ab_focused_holo_dark 0x7f020058
int drawable abs__spinner_ab_focused_holo_light 0x7f020059
int drawable abs__spinner_ab_holo_dark 0x7f02005a
int drawable abs__spinner_ab_holo_light 0x7f02005b
int drawable abs__spinner_ab_pressed_holo_dark 0x7f02005c
int drawable abs__spinner_ab_pressed_holo_light 0x7f02005d
int drawable abs__tab_indicator_ab_holo 0x7f02005e
int drawable abs__tab_selected_focused_holo 0x7f02005f
int drawable abs__tab_selected_holo 0x7f020060
int drawable abs__tab_selected_pressed_holo 0x7f020061
int drawable abs__tab_unselected_pressed_holo 0x7f020062
int drawable abs__textfield_search_default_holo_dark 0x7f020063
int drawable abs__textfield_search_default_holo_light 0x7f020064
int drawable abs__textfield_search_right_default_holo_dark 0x7f020065
int drawable abs__textfield_search_right_default_holo_light 0x7f020066
int drawable abs__textfield_search_right_selected_holo_dark 0x7f020067
int drawable abs__textfield_search_right_selected_holo_light 0x7f020068
int drawable abs__textfield_search_selected_holo_dark 0x7f020069
int drawable abs__textfield_search_selected_holo_light 0x7f02006a
int drawable abs__textfield_searchview_holo_dark 0x7f02006b
int drawable abs__textfield_searchview_holo_light 0x7f02006c
int drawable abs__textfield_searchview_right_holo_dark 0x7f02006d
int drawable abs__textfield_searchview_right_holo_light 0x7f02006e
int drawable appinstall 0x7f02006f
int drawable applist 0x7f020070
int drawable appuninstall 0x7f020071
int drawable btn_grey 0x7f020072
int drawable btn_orange 0x7f020073
int drawable camera 0x7f020074
int drawable changepassword 0x7f020075
int drawable custom_checkbox 0x7f020076
int drawable dot 0x7f020077
int drawable encrypt 0x7f020078
int drawable ic_bookmark 0x7f020079
int drawable ic_check_default 0x7f02007a
int drawable ic_check_selected 0x7f02007b
int drawable ic_launcher 0x7f02007c
int drawable ic_logo 0x7f02007d
int drawable ic_logo_dark 0x7f02007e
int drawable ic_stat_gcm 0x7f02007f
int drawable info 0x7f020080
int drawable location 0x7f020081
int drawable lock 0x7f020082
int drawable mdm_logo 0x7f020083
int drawable mute 0x7f020084
int drawable notification 0x7f020085
int drawable option_icon 0x7f020086
int drawable repeat_bg 0x7f020087
int drawable top_bar 0x7f020088
int drawable wifi 0x7f020089
int drawable wipe 0x7f02008a
int id TextView01 0x7f060091
int id abs__action_bar 0x7f06004e
int id abs__action_bar_container 0x7f06004d
int id abs__action_bar_subtitle 0x7f06003d
int id abs__action_bar_title 0x7f06003c
int id abs__action_context_bar 0x7f06004f
int id abs__action_menu_divider 0x7f06000c
int id abs__action_menu_presenter 0x7f06000d
int id abs__action_mode_bar 0x7f060052
int id abs__action_mode_bar_stub 0x7f060051
int id abs__action_mode_close_button 0x7f060040
int id abs__activity_chooser_view_content 0x7f060041
int id abs__checkbox 0x7f06004a
int id abs__content 0x7f060049
int id abs__default_activity_button 0x7f060044
int id abs__expand_activities_button 0x7f060042
int id abs__home 0x7f06000a
int id abs__icon 0x7f060046
int id abs__image 0x7f060043
int id abs__imageButton 0x7f06003e
int id abs__list_item 0x7f060045
int id abs__progress_circular 0x7f06000e
int id abs__progress_horizontal 0x7f06000f
int id abs__radio 0x7f06004c
int id abs__search_badge 0x7f060055
int id abs__search_bar 0x7f060054
int id abs__search_button 0x7f060056
int id abs__search_close_btn 0x7f06005b
int id abs__search_edit_frame 0x7f060057
int id abs__search_go_btn 0x7f06005d
int id abs__search_mag_icon 0x7f060058
int id abs__search_plate 0x7f060059
int id abs__search_src_text 0x7f06005a
int id abs__search_voice_btn 0x7f06005e
int id abs__shortcut 0x7f06004b
int id abs__split_action_bar 0x7f060050
int id abs__submit_area 0x7f06005c
int id abs__textButton 0x7f06003f
int id abs__title 0x7f060047
int id abs__titleDivider 0x7f060048
int id abs__up 0x7f06000b
int id action_settings 0x7f060095
int id background_container 0x7f06001f
int id blocks_now 0x7f06001e
int id blocks_ruler 0x7f06001d
int id btnEnroll 0x7f060082
int id btnLogin 0x7f060090
int id btnOK 0x7f060064
int id btnRefresh 0x7f06007d
int id btnRegister 0x7f060070
int id btnReset 0x7f06007e
int id btnSetPin 0x7f060087
int id btnStartRegistration 0x7f06008b
int id btnTryAgain 0x7f060073
int id btnUnreg 0x7f060065
int id btnUnregister 0x7f060088
int id button_layout 0x7f06008d
int id debug_log 0x7f06009b
int id dialogButtonCancel 0x7f06008f
int id dialogButtonOK 0x7f06008e
int id dialog_discard_confirm 0x7f06001a
int id dialog_moderator 0x7f06001b
int id dialog_wave 0x7f06001c
int id disableHome 0x7f060009
int id edit_query 0x7f060053
int id enrollPanel 0x7f060081
int id error 0x7f060072
int id etDomain 0x7f06006a
int id etPassword 0x7f06006c
int id etUsername 0x7f06006b
int id evServerIP 0x7f06008a
int id footer 0x7f060071
int id footerlogo 0x7f060068
int id fragment_container 0x7f060034
int id gridview 0x7f060014
int id homeAsUp 0x7f060006
int id incompatibleError 0x7f060074
int id info 0x7f060098
int id info_setting 0x7f060099
int id ip_setting 0x7f060097
int id layout_topbar 0x7f060067
int id lblPin 0x7f060084
int id linInner 0x7f060062
int id linearLayout1 0x7f060069
int id linearLayoutText 0x7f060080
int id listMode 0x7f060002
int id listview 0x7f060060
int id logo 0x7f06005f
int id more 0x7f060096
int id normal 0x7f060001
int id notify 0x7f060092
int id option_button 0x7f06007c
int id pin_setting 0x7f06009a
int id preference_brand_view 0x7f06002d
int id preference_empty_view 0x7f06002c
int id radioBYOD 0x7f06006e
int id radioCOPE 0x7f06006f
int id radioGroupType 0x7f06006d
int id rowImage 0x7f060093
int id rowTextView 0x7f060094
int id scroller 0x7f060061
int id setting_invite_email_button 0x7f060030
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 sg_button1 0x7f060039
int id sg_button2 0x7f06003a
int id sg_button3 0x7f06003b
int id sg_category_popup 0x7f060035
int id sg_city 0x7f060038
int id sg_tag_command 0x7f060036
int id sg_tag_payload 0x7f060037
int id showCustom 0x7f060008
int id showHome 0x7f060005
int id showTitle 0x7f060007
int id sp_edittext_city 0x7f060025
int id sp_edittext_email 0x7f060023
int id sp_edittext_location 0x7f060022
int id sp_edittext_name 0x7f060021
int id sp_edittext_other 0x7f06002a
int id sp_edittext_phone 0x7f060029
int id sp_edittext_state 0x7f060026
int id sp_edittext_street 0x7f060024
int id sp_edittext_zipcode 0x7f060027
int id sp_textview_country 0x7f060028
int id sp_textview_gpspick 0x7f06002b
int id startRegistration 0x7f060083
int id swipeable 0x7f060013
int id swipeable_bottom 0x7f060010
int id swipeable_container 0x7f060012
int id swipeable_top 0x7f060011
int id tabMode 0x7f060003
int id text 0x7f06008c
int id title_bar_layout 0x7f060020
int id title_container 0x7f060016
int id title_logo 0x7f060017
int id title_option 0x7f060019
int id title_text 0x7f060018
int id tvSeverAddress 0x7f060089
int id txtDevice 0x7f060076
int id txtId 0x7f060075
int id txtLog 0x7f06007f
int id txtMessage 0x7f060063
int id txtModel 0x7f060077
int id txtOS 0x7f06007a
int id txtOldPinCode 0x7f060085
int id txtOperator 0x7f060078
int id txtPinCode 0x7f060086
int id txtRegText 0x7f060066
int id txtRoot 0x7f06007b
int id txtSDK 0x7f060079
int id useLogo 0x7f060004
int id user_edit_location 0x7f060033
int id webview 0x7f060015
int id wrap_content 0x7f060000
int integer abs__max_action_buttons 0x7f0a0000
int layout abs__action_bar_home 0x7f030000
int layout abs__action_bar_tab 0x7f030001
int layout abs__action_bar_tab_bar_view 0x7f030002
int layout abs__action_bar_title_item 0x7f030003
int layout abs__action_menu_item_layout 0x7f030004
int layout abs__action_menu_layout 0x7f030005
int layout abs__action_mode_bar 0x7f030006
int layout abs__action_mode_close_item 0x7f030007
int layout abs__activity_chooser_view 0x7f030008
int layout abs__activity_chooser_view_list_item 0x7f030009
int layout abs__dialog_title_holo 0x7f03000a
int layout abs__list_menu_item_checkbox 0x7f03000b
int layout abs__list_menu_item_icon 0x7f03000c
int layout abs__list_menu_item_layout 0x7f03000d
int layout abs__list_menu_item_radio 0x7f03000e
int layout abs__popup_menu_item_layout 0x7f03000f
int layout abs__screen_action_bar 0x7f030010
int layout abs__screen_action_bar_overlay 0x7f030011
int layout abs__screen_simple 0x7f030012
int layout abs__screen_simple_overlay_action_mode 0x7f030013
int layout abs__search_dropdown_item_icons_2line 0x7f030014
int layout abs__search_view 0x7f030015
int layout abs__simple_dropdown_hint 0x7f030016
int layout activity_agent_settings 0x7f030017
int layout activity_alert 0x7f030018
int layout activity_already_registered 0x7f030019
int layout activity_authentication 0x7f03001a
int layout activity_authentication_error 0x7f03001b
int layout activity_available_operations 0x7f03001c
int layout activity_display_device_info 0x7f03001d
int layout activity_entry 0x7f03001e
int layout activity_log 0x7f03001f
int layout activity_main 0x7f030020
int layout activity_notification 0x7f030021
int layout activity_pin_code 0x7f030022
int layout activity_register_successful 0x7f030023
int layout activity_settings 0x7f030024
int layout custom_sherlock_bar 0x7f030025
int layout custom_terms_popup 0x7f030026
int layout footer_repeat 0x7f030027
int layout header_gradient 0x7f030028
int layout login 0x7f030029
int layout main 0x7f03002a
int layout notify 0x7f03002b
int layout row_with_icon 0x7f03002c
int layout sherlock_spinner_dropdown_item 0x7f03002d
int layout sherlock_spinner_item 0x7f03002e
int layout simplerow 0x7f03002f
int menu agent_settings 0x7f0d0000
int menu alert 0x7f0d0001
int menu all_ready_registered 0x7f0d0002
int menu auth_sherlock_menu 0x7f0d0003
int menu authentication 0x7f0d0004
int menu authentication_error 0x7f0d0005
int menu available_operations 0x7f0d0006
int menu display_device_info 0x7f0d0007
int menu entry 0x7f0d0008
int menu log 0x7f0d0009
int menu main 0x7f0d000a
int menu notification 0x7f0d000b
int menu notify 0x7f0d000c
int menu options_menu 0x7f0d000d
int menu pin_code 0x7f0d000e
int menu register_successful 0x7f0d000f
int menu settings 0x7f0d0010
int menu sherlock_menu 0x7f0d0011
int menu sherlock_menu_debug 0x7f0d0012
int raw emm_truststore 0x7f050000
int string abs__action_bar_home_description 0x7f0b0000
int string abs__action_bar_up_description 0x7f0b0001
int string abs__action_menu_overflow_description 0x7f0b0002
int string abs__action_mode_done 0x7f0b0003
int string abs__activity_chooser_view_dialog_title_default 0x7f0b0005
int string abs__activity_chooser_view_see_all 0x7f0b0004
int string abs__activitychooserview_choose_application 0x7f0b0007
int string abs__searchview_description_clear 0x7f0b000c
int string abs__searchview_description_query 0x7f0b000b
int string abs__searchview_description_search 0x7f0b000a
int string abs__searchview_description_submit 0x7f0b000d
int string abs__searchview_description_voice 0x7f0b000e
int string abs__share_action_provider_share_with 0x7f0b0006
int string abs__shareactionprovider_share_with 0x7f0b0008
int string abs__shareactionprovider_share_with_application 0x7f0b0009
int string action_settings 0x7f0b0025
int string already_registered 0x7f0b0012
int string app_name 0x7f0b0023
int string application_mgr_download_file_name 0x7f0b0097
int string application_mgr_download_location 0x7f0b0096
int string application_mgr_mime 0x7f0b0098
int string application_package_launcher_action 0x7f0b009a
int string application_package_prefix 0x7f0b0099
int string button_cancel 0x7f0b0095
int string button_ok 0x7f0b0094
int string client_id 0x7f0b000f
int string client_secret 0x7f0b0010
int string device_admin_disabled 0x7f0b0030
int string device_admin_enable_alert 0x7f0b003f
int string device_admin_enabled 0x7f0b002f
int string device_compatible 0x7f0b0033
int string device_enroll_type_byod 0x7f0b0040
int string device_enroll_type_cope 0x7f0b0041
int string device_not_compatible_error 0x7f0b0031
int string device_not_compatible_error_os 0x7f0b0032
int string device_not_compatible_error_root 0x7f0b0034
int string dialog_authenticate 0x7f0b0075
int string dialog_checking_reg 0x7f0b0077
int string dialog_enrolling 0x7f0b007a
int string dialog_init_confirmation 0x7f0b007d
int string dialog_init_device_type 0x7f0b007f
int string dialog_init_end 0x7f0b0080
int string dialog_init_end_general 0x7f0b0081
int string dialog_init_middle 0x7f0b007e
int string dialog_license_agreement 0x7f0b0079
int string dialog_message_please_wait 0x7f0b0089
int string dialog_message_unregistering 0x7f0b0088
int string dialog_pin_confirmation 0x7f0b007b
int string dialog_pin_confirmation_end 0x7f0b007c
int string dialog_please_wait 0x7f0b0076
int string dialog_sender_id 0x7f0b0078
int string dialog_unregister 0x7f0b0082
int string empty_app_title 0x7f0b0024
int string error_auth_failed_detail 0x7f0b006c
int string error_authentication_failed 0x7f0b006d
int string error_authorization_failed 0x7f0b0069
int string error_config 0x7f0b0011
int string error_connect_to_server 0x7f0b0065
int string error_enrollment_failed 0x7f0b006a
int string error_enrollment_failed_detail 0x7f0b006b
int string error_for_all_unknown_authentication_failures 0x7f0b0070
int string error_for_all_unknown_notification_failures 0x7f0b0072
int string error_for_all_unknown_registration_failures 0x7f0b006f
int string error_for_all_unknown_unregister_failures 0x7f0b0071
int string error_heading_connection 0x7f0b0066
int string error_internal_server 0x7f0b0073
int string error_invalid_server_address 0x7f0b0074
int string error_network_unavailable 0x7f0b006e
int string error_registration_failed 0x7f0b0067
int string error_unregistration_failed 0x7f0b0068
int string gcm_deleted 0x7f0b0018
int string gcm_error 0x7f0b0016
int string gcm_message 0x7f0b0015
int string gcm_recoverable_error 0x7f0b0017
int string gcm_registered 0x7f0b0013
int string gcm_unregistered 0x7f0b0014
int string hello_world 0x7f0b0026
int string hint_new_pin 0x7f0b0045
int string info_label_device 0x7f0b008b
int string info_label_imei 0x7f0b008a
int string info_label_imsi 0x7f0b008f
int string info_label_model 0x7f0b008c
int string info_label_no_sim 0x7f0b008d
int string info_label_operator 0x7f0b008e
int string info_label_os 0x7f0b0090
int string info_label_rooted 0x7f0b0091
int string intent_extra_fresh_reg_flag 0x7f0b004f
int string intent_extra_from_activity 0x7f0b004b
int string intent_extra_main_activity 0x7f0b004d
int string intent_extra_message 0x7f0b004e
int string intent_extra_notification 0x7f0b0051
int string intent_extra_regid 0x7f0b004c
int string intent_extra_username 0x7f0b0050
int string menu_item_change_ip 0x7f0b0087
int string menu_item_change_pin 0x7f0b0086
int string menu_item_ip 0x7f0b003c
int string menu_item_log 0x7f0b003d
int string menu_item_operations 0x7f0b003a
int string menu_item_phone_info 0x7f0b0085
int string menu_item_pin 0x7f0b003b
int string no 0x7f0b0093
int string options_clear 0x7f0b0021
int string options_exit 0x7f0b0022
int string options_register 0x7f0b001e
int string options_unregister 0x7f0b001f
int string register_button_text 0x7f0b0083
int string register_text_view_text_unregister 0x7f0b0084
int string registration_heading 0x7f0b009e
int string server_register_error 0x7f0b001c
int string server_registered 0x7f0b001a
int string server_registering 0x7f0b0019
int string server_unregister_error 0x7f0b001d
int string server_unregistered 0x7f0b001b
int string server_util_req_type_get 0x7f0b009c
int string server_util_req_type_post 0x7f0b009b
int string shared_pref_client_id 0x7f0b0063
int string shared_pref_client_secret 0x7f0b0064
int string shared_pref_device_active 0x7f0b0062
int string shared_pref_eula 0x7f0b0057
int string shared_pref_interval 0x7f0b0060
int string shared_pref_ip 0x7f0b0056
int string shared_pref_isagreed 0x7f0b0054
int string shared_pref_message_mode 0x7f0b005f
int string shared_pref_package 0x7f0b0052
int string shared_pref_pin 0x7f0b005a
int string shared_pref_policy 0x7f0b0053
int string shared_pref_regId 0x7f0b0058
int string shared_pref_reg_fail 0x7f0b005c
int string shared_pref_reg_success 0x7f0b005b
int string shared_pref_reg_type 0x7f0b005d
int string shared_pref_registered 0x7f0b0055
int string shared_pref_sender_id 0x7f0b005e
int string shared_pref_username 0x7f0b0059
int string string_content 0x7f0b0020
int string title_activity_agent_settings 0x7f0b0038
int string title_activity_alert 0x7f0b003e
int string title_activity_authentication_error 0x7f0b0035
int string title_activity_available_operations 0x7f0b0039
int string title_activity_display_device_info 0x7f0b0027
int string title_activity_entry 0x7f0b002a
int string title_activity_log 0x7f0b009d
int string title_activity_notification 0x7f0b0036
int string title_activity_notify 0x7f0b0037
int string title_activity_register_successful 0x7f0b0029
int string title_head_authentication_error 0x7f0b002b
int string title_head_confirm_pin 0x7f0b0044
int string title_head_connection_error 0x7f0b002d
int string title_head_init_error 0x7f0b0043
int string title_head_notification_error 0x7f0b002e
int string title_head_registration_error 0x7f0b002c
int string title_init_msg_error 0x7f0b0042
int string toast_error_password 0x7f0b004a
int string toast_error_username 0x7f0b0049
int string toast_message_enter_server_address 0x7f0b0048
int string toast_message_pin_change_failed 0x7f0b0047
int string toast_message_pin_change_success 0x7f0b0046
int string url 0x7f0b0028
int string username 0x7f0b0061
int string validation_pin_confirm 0x7f0b009f
int string yes 0x7f0b0092
int style AppBaseTheme 0x7f0c0059
int style AppTheme 0x7f0c005a
int style ButtonText 0x7f0c005f
int style DialogWindowTitle_Sherlock 0x7f0c0036
int style DialogWindowTitle_Sherlock_Light 0x7f0c0037
int style Sherlock___TextAppearance_Small 0x7f0c004a
int style Sherlock___Theme 0x7f0c004e
int style Sherlock___Theme_DarkActionBar 0x7f0c0050
int style Sherlock___Theme_Dialog 0x7f0c0051
int style Sherlock___Theme_Light 0x7f0c004f
int style Sherlock___Widget_ActionBar 0x7f0c0001
int style Sherlock___Widget_ActionMode 0x7f0c0016
int style Sherlock___Widget_ActivityChooserView 0x7f0c001e
int style Sherlock___Widget_Holo_DropDownItem 0x7f0c0029
int style Sherlock___Widget_Holo_ListView 0x7f0c0026
int style Sherlock___Widget_Holo_Spinner 0x7f0c0023
int style Sherlock___Widget_SearchAutoCompleteTextView 0x7f0c0033
int style TextAppearance_Sherlock_DialogWindowTitle 0x7f0c0048
int style TextAppearance_Sherlock_Light_DialogWindowTitle 0x7f0c0049
int style TextAppearance_Sherlock_Light_Small 0x7f0c004c
int style TextAppearance_Sherlock_Light_Widget_PopupMenu_Large 0x7f0c0043
int style TextAppearance_Sherlock_Light_Widget_PopupMenu_Small 0x7f0c0045
int style TextAppearance_Sherlock_Small 0x7f0c004b
int style TextAppearance_Sherlock_Widget_ActionBar_Menu 0x7f0c0038
int style TextAppearance_Sherlock_Widget_ActionBar_Subtitle 0x7f0c003b
int style TextAppearance_Sherlock_Widget_ActionBar_Subtitle_Inverse 0x7f0c003c
int style TextAppearance_Sherlock_Widget_ActionBar_Title 0x7f0c0039
int style TextAppearance_Sherlock_Widget_ActionBar_Title_Inverse 0x7f0c003a
int style TextAppearance_Sherlock_Widget_ActionMode_Subtitle 0x7f0c003f
int style TextAppearance_Sherlock_Widget_ActionMode_Subtitle_Inverse 0x7f0c0040
int style TextAppearance_Sherlock_Widget_ActionMode_Title 0x7f0c003d
int style TextAppearance_Sherlock_Widget_ActionMode_Title_Inverse 0x7f0c003e
int style TextAppearance_Sherlock_Widget_DropDownHint 0x7f0c004d
int style TextAppearance_Sherlock_Widget_DropDownItem 0x7f0c0047
int style TextAppearance_Sherlock_Widget_PopupMenu 0x7f0c0041
int style TextAppearance_Sherlock_Widget_PopupMenu_Large 0x7f0c0042
int style TextAppearance_Sherlock_Widget_PopupMenu_Small 0x7f0c0044
int style TextAppearance_Sherlock_Widget_TextView_SpinnerItem 0x7f0c0046
int style Theme_Sherlock 0x7f0c0052
int style Theme_Sherlock_Dialog 0x7f0c0057
int style Theme_Sherlock_Light 0x7f0c0053
int style Theme_Sherlock_Light_DarkActionBar 0x7f0c0054
int style Theme_Sherlock_Light_Dialog 0x7f0c0058
int style Theme_Sherlock_Light_NoActionBar 0x7f0c0056
int style Theme_Sherlock_NoActionBar 0x7f0c0055
int style TitleBar 0x7f0c005c
int style TitleBarLogo 0x7f0c005d
int style TitleBarOption 0x7f0c005e
int style TopBarTheme 0x7f0c005b
int style Widget 0x7f0c0000
int style Widget_Sherlock_ActionBar 0x7f0c0002
int style Widget_Sherlock_ActionBar_Solid 0x7f0c0003
int style Widget_Sherlock_ActionBar_TabBar 0x7f0c000a
int style Widget_Sherlock_ActionBar_TabText 0x7f0c000d
int style Widget_Sherlock_ActionBar_TabView 0x7f0c0007
int style Widget_Sherlock_ActionButton 0x7f0c0010
int style Widget_Sherlock_ActionButton_CloseMode 0x7f0c0012
int style Widget_Sherlock_ActionButton_Overflow 0x7f0c0014
int style Widget_Sherlock_ActionMode 0x7f0c0017
int style Widget_Sherlock_ActivityChooserView 0x7f0c001f
int style Widget_Sherlock_Button_Small 0x7f0c0021
int style Widget_Sherlock_DropDownItem_Spinner 0x7f0c002a
int style Widget_Sherlock_Light_ActionBar 0x7f0c0004
int style Widget_Sherlock_Light_ActionBar_Solid 0x7f0c0005
int style Widget_Sherlock_Light_ActionBar_Solid_Inverse 0x7f0c0006
int style Widget_Sherlock_Light_ActionBar_TabBar 0x7f0c000b
int style Widget_Sherlock_Light_ActionBar_TabBar_Inverse 0x7f0c000c
int style Widget_Sherlock_Light_ActionBar_TabText 0x7f0c000e
int style Widget_Sherlock_Light_ActionBar_TabText_Inverse 0x7f0c000f
int style Widget_Sherlock_Light_ActionBar_TabView 0x7f0c0008
int style Widget_Sherlock_Light_ActionBar_TabView_Inverse 0x7f0c0009
int style Widget_Sherlock_Light_ActionButton 0x7f0c0011
int style Widget_Sherlock_Light_ActionButton_CloseMode 0x7f0c0013
int style Widget_Sherlock_Light_ActionButton_Overflow 0x7f0c0015
int style Widget_Sherlock_Light_ActionMode 0x7f0c0018
int style Widget_Sherlock_Light_ActionMode_Inverse 0x7f0c0019
int style Widget_Sherlock_Light_ActivityChooserView 0x7f0c0020
int style Widget_Sherlock_Light_Button_Small 0x7f0c0022
int style Widget_Sherlock_Light_DropDownItem_Spinner 0x7f0c002b
int style Widget_Sherlock_Light_ListPopupWindow 0x7f0c001b
int style Widget_Sherlock_Light_ListView_DropDown 0x7f0c0028
int style Widget_Sherlock_Light_PopupMenu 0x7f0c001d
int style Widget_Sherlock_Light_PopupWindow_ActionMode 0x7f0c002d
int style Widget_Sherlock_Light_ProgressBar 0x7f0c002f
int style Widget_Sherlock_Light_ProgressBar_Horizontal 0x7f0c0031
int style Widget_Sherlock_Light_SearchAutoCompleteTextView 0x7f0c0035
int style Widget_Sherlock_Light_Spinner_DropDown_ActionBar 0x7f0c0025
int style Widget_Sherlock_ListPopupWindow 0x7f0c001a
int style Widget_Sherlock_ListView_DropDown 0x7f0c0027
int style Widget_Sherlock_PopupMenu 0x7f0c001c
int style Widget_Sherlock_PopupWindow_ActionMode 0x7f0c002c
int style Widget_Sherlock_ProgressBar 0x7f0c002e
int style Widget_Sherlock_ProgressBar_Horizontal 0x7f0c0030
int style Widget_Sherlock_SearchAutoCompleteTextView 0x7f0c0034
int style Widget_Sherlock_Spinner_DropDown_ActionBar 0x7f0c0024
int style Widget_Sherlock_TextView_SpinnerItem 0x7f0c0032
int[] styleable SherlockActionBar { 0x7f010000, 0x7f010001, 0x7f010002, 0x7f010003, 0x7f010004, 0x7f010005, 0x7f010048, 0x7f010049, 0x7f01004a, 0x7f01004b, 0x7f01004c, 0x7f01004d, 0x7f01004e, 0x7f01004f, 0x7f010050, 0x7f010051, 0x7f010052, 0x7f010053, 0x7f010054 }
int styleable SherlockActionBar_background 2
int styleable SherlockActionBar_backgroundSplit 3
int styleable SherlockActionBar_backgroundStacked 12
int styleable SherlockActionBar_customNavigationLayout 13
int styleable SherlockActionBar_displayOptions 7
int styleable SherlockActionBar_divider 5
int styleable SherlockActionBar_height 4
int styleable SherlockActionBar_homeLayout 14
int styleable SherlockActionBar_icon 10
int styleable SherlockActionBar_indeterminateProgressStyle 16
int styleable SherlockActionBar_itemPadding 18
int styleable SherlockActionBar_logo 11
int styleable SherlockActionBar_navigationMode 6
int styleable SherlockActionBar_progressBarPadding 17
int styleable SherlockActionBar_progressBarStyle 15
int styleable SherlockActionBar_subtitle 9
int styleable SherlockActionBar_subtitleTextStyle 1
int styleable SherlockActionBar_title 8
int styleable SherlockActionBar_titleTextStyle 0
int[] styleable SherlockActionMenuItemView { 0x0101013f }
int styleable SherlockActionMenuItemView_android_minWidth 0
int[] styleable SherlockActionMode { 0x7f010000, 0x7f010001, 0x7f010002, 0x7f010003, 0x7f010004 }
int styleable SherlockActionMode_background 2
int styleable SherlockActionMode_backgroundSplit 3
int styleable SherlockActionMode_height 4
int styleable SherlockActionMode_subtitleTextStyle 1
int styleable SherlockActionMode_titleTextStyle 0
int[] styleable SherlockActivityChooserView { 0x010100d4, 0x7f01005d, 0x7f01005e }
int styleable SherlockActivityChooserView_android_background 0
int styleable SherlockActivityChooserView_expandActivityOverflowButtonDrawable 2
int styleable SherlockActivityChooserView_initialActivityCount 1
int[] styleable SherlockMenuGroup { 0x0101000e, 0x010100d0, 0x01010194, 0x010101de, 0x010101df, 0x010101e0 }
int styleable SherlockMenuGroup_android_checkableBehavior 5
int styleable SherlockMenuGroup_android_enabled 0
int styleable SherlockMenuGroup_android_id 1
int styleable SherlockMenuGroup_android_menuCategory 3
int styleable SherlockMenuGroup_android_orderInCategory 4
int styleable SherlockMenuGroup_android_visible 2
int[] styleable SherlockMenuItem { 0x01010002, 0x0101000e, 0x010100d0, 0x01010106, 0x01010194, 0x010101de, 0x010101df, 0x010101e1, 0x010101e2, 0x010101e3, 0x010101e4, 0x010101e5, 0x0101026f, 0x010102d9, 0x010102fb, 0x010102fc, 0x01010389 }
int styleable SherlockMenuItem_android_actionLayout 14
int styleable SherlockMenuItem_android_actionProviderClass 16
int styleable SherlockMenuItem_android_actionViewClass 15
int styleable SherlockMenuItem_android_alphabeticShortcut 9
int styleable SherlockMenuItem_android_checkable 11
int styleable SherlockMenuItem_android_checked 3
int styleable SherlockMenuItem_android_enabled 1
int styleable SherlockMenuItem_android_icon 0
int styleable SherlockMenuItem_android_id 2
int styleable SherlockMenuItem_android_menuCategory 5
int styleable SherlockMenuItem_android_numericShortcut 10
int styleable SherlockMenuItem_android_onClick 12
int styleable SherlockMenuItem_android_orderInCategory 6
int styleable SherlockMenuItem_android_showAsAction 13
int styleable SherlockMenuItem_android_title 7
int styleable SherlockMenuItem_android_titleCondensed 8
int styleable SherlockMenuItem_android_visible 4
int[] styleable SherlockMenuView { 0x7f010055, 0x7f010056, 0x7f010057, 0x7f010058, 0x7f010059, 0x7f01005a, 0x7f01005b, 0x7f01005c }
int styleable SherlockMenuView_headerBackground 3
int styleable SherlockMenuView_horizontalDivider 1
int styleable SherlockMenuView_itemBackground 4
int styleable SherlockMenuView_itemIconDisabledAlpha 6
int styleable SherlockMenuView_itemTextAppearance 0
int styleable SherlockMenuView_preserveIconSpacing 7
int styleable SherlockMenuView_verticalDivider 2
int styleable SherlockMenuView_windowAnimationStyle 5
int[] styleable SherlockSearchView { 0x0101011f, 0x01010220, 0x01010264, 0x7f01005f, 0x7f010060 }
int styleable SherlockSearchView_android_imeOptions 2
int styleable SherlockSearchView_android_inputType 1
int styleable SherlockSearchView_android_maxWidth 0
int styleable SherlockSearchView_iconifiedByDefault 3
int styleable SherlockSearchView_queryHint 4
int[] styleable SherlockSpinner { 0x010100af, 0x01010175, 0x01010176, 0x0101017b, 0x01010262, 0x010102ac, 0x010102ad, 0x0101043a }
int styleable SherlockSpinner_android_dropDownHorizontalOffset 5
int styleable SherlockSpinner_android_dropDownSelector 1
int styleable SherlockSpinner_android_dropDownVerticalOffset 6
int styleable SherlockSpinner_android_dropDownWidth 4
int styleable SherlockSpinner_android_gravity 0
int styleable SherlockSpinner_android_popupBackground 2
int styleable SherlockSpinner_android_popupPromptView 7
int styleable SherlockSpinner_android_prompt 3
int[] styleable SherlockTheme { 0x01010057, 0x7f010006, 0x7f010007, 0x7f010008, 0x7f010009, 0x7f01000a, 0x7f01000b, 0x7f01000c, 0x7f01000d, 0x7f01000e, 0x7f01000f, 0x7f010010, 0x7f010011, 0x7f010012, 0x7f010013, 0x7f010014, 0x7f010015, 0x7f010016, 0x7f010017, 0x7f010018, 0x7f010019, 0x7f01001a, 0x7f01001b, 0x7f01001c, 0x7f01001d, 0x7f01001e, 0x7f01001f, 0x7f010020, 0x7f010021, 0x7f010022, 0x7f010023, 0x7f010024, 0x7f010025, 0x7f010026, 0x7f010027, 0x7f010028, 0x7f010029, 0x7f01002a, 0x7f01002b, 0x7f01002c, 0x7f01002d, 0x7f01002e, 0x7f01002f, 0x7f010030, 0x7f010031, 0x7f010032, 0x7f010033, 0x7f010034, 0x7f010035, 0x7f010036, 0x7f010037, 0x7f010038, 0x7f010039, 0x7f01003a, 0x7f01003b, 0x7f01003c, 0x7f01003d, 0x7f01003e, 0x7f01003f, 0x7f010040, 0x7f010041, 0x7f010042, 0x7f010043, 0x7f010044, 0x7f010045, 0x7f010046, 0x7f010047 }
int styleable SherlockTheme_actionBarDivider 9
int styleable SherlockTheme_actionBarItemBackground 10
int styleable SherlockTheme_actionBarSize 8
int styleable SherlockTheme_actionBarSplitStyle 6
int styleable SherlockTheme_actionBarStyle 5
int styleable SherlockTheme_actionBarTabBarStyle 2
int styleable SherlockTheme_actionBarTabStyle 1
int styleable SherlockTheme_actionBarTabTextStyle 3
int styleable SherlockTheme_actionBarWidgetTheme 7
int styleable SherlockTheme_actionButtonStyle 53
int styleable SherlockTheme_actionDropDownStyle 52
int styleable SherlockTheme_actionMenuTextAppearance 11
int styleable SherlockTheme_actionMenuTextColor 12
int styleable SherlockTheme_actionModeBackground 15
int styleable SherlockTheme_actionModeCloseButtonStyle 14
int styleable SherlockTheme_actionModeCloseDrawable 17
int styleable SherlockTheme_actionModePopupWindowStyle 19
int styleable SherlockTheme_actionModeShareDrawable 18
int styleable SherlockTheme_actionModeSplitBackground 16
int styleable SherlockTheme_actionModeStyle 13
int styleable SherlockTheme_actionOverflowButtonStyle 4
int styleable SherlockTheme_actionSpinnerItemStyle 58
int styleable SherlockTheme_activatedBackgroundIndicator 66
int styleable SherlockTheme_activityChooserViewStyle 65
int styleable SherlockTheme_android_windowIsFloating 0
int styleable SherlockTheme_buttonStyleSmall 20
int styleable SherlockTheme_dividerVertical 51
int styleable SherlockTheme_dropDownListViewStyle 55
int styleable SherlockTheme_dropdownListPreferredItemHeight 57
int styleable SherlockTheme_homeAsUpIndicator 54
int styleable SherlockTheme_listPopupWindowStyle 64
int styleable SherlockTheme_listPreferredItemHeightSmall 45
int styleable SherlockTheme_listPreferredItemPaddingLeft 46
int styleable SherlockTheme_listPreferredItemPaddingRight 47
int styleable SherlockTheme_popupMenuStyle 56
int styleable SherlockTheme_searchAutoCompleteTextView 31
int styleable SherlockTheme_searchDropdownBackground 32
int styleable SherlockTheme_searchResultListItemHeight 42
int styleable SherlockTheme_searchViewCloseIcon 33
int styleable SherlockTheme_searchViewEditQuery 37
int styleable SherlockTheme_searchViewEditQueryBackground 38
int styleable SherlockTheme_searchViewGoIcon 34
int styleable SherlockTheme_searchViewSearchIcon 35
int styleable SherlockTheme_searchViewTextField 39
int styleable SherlockTheme_searchViewTextFieldRight 40
int styleable SherlockTheme_searchViewVoiceIcon 36
int styleable SherlockTheme_selectableItemBackground 21
int styleable SherlockTheme_spinnerDropDownItemStyle 30
int styleable SherlockTheme_spinnerItemStyle 29
int styleable SherlockTheme_textAppearanceLargePopupMenu 23
int styleable SherlockTheme_textAppearanceListItemSmall 48
int styleable SherlockTheme_textAppearanceSearchResultSubtitle 44
int styleable SherlockTheme_textAppearanceSearchResultTitle 43
int styleable SherlockTheme_textAppearanceSmall 25
int styleable SherlockTheme_textAppearanceSmallPopupMenu 24
int styleable SherlockTheme_textColorPrimary 26
int styleable SherlockTheme_textColorPrimaryDisableOnly 27
int styleable SherlockTheme_textColorPrimaryInverse 28
int styleable SherlockTheme_textColorSearchUrl 41
int styleable SherlockTheme_windowActionBar 60
int styleable SherlockTheme_windowActionBarOverlay 61
int styleable SherlockTheme_windowActionModeOverlay 62
int styleable SherlockTheme_windowContentOverlay 22
int styleable SherlockTheme_windowMinWidthMajor 49
int styleable SherlockTheme_windowMinWidthMinor 50
int styleable SherlockTheme_windowNoTitle 59
int styleable SherlockTheme_windowSplitActionBar 63
int[] styleable SherlockView { 0x010100da }
int styleable SherlockView_android_focusable 0
int xml wso2_device_admin 0x7f040000

View File

@ -1,5 +0,0 @@
# cache for current jar dependency. DO NOT EDIT.
# format is <lastModified> <length> <SHA-1> <path>
# Encoding is UTF-8
1421928865000 484258 bd6479f5dd592790607e0504e66e0f31c2b4d308 /home/inoshp/Documents/work/EMM 2.0/Source/CDM/product-mdm/product/modules/agents/android/client/libs/android-support-v4.jar
1421928865000 484258 bd6479f5dd592790607e0504e66e0f31c2b4d308 /home/inoshp/Documents/work/EMM 2.0/Source/CDM/product-mdm/product/modules/agents/android/client/plugins/ActionBarSherlock/library/libs/android-support-v4.jar

View File

@ -1,110 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<project name="client" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties"/>
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties"/>
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env"/>
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME"/>
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties"/>
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true"/>
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml"/>
</project>

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockActivity;
import org.wso2.mdm.agent.R;
public class AlertActivity extends SherlockActivity {
private String message;
private Button btnOK;
private TextView txtMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alert);
btnOK = (Button) findViewById(R.id.btnOK);
txtMessage = (TextView) findViewById(R.id.txtMessage);
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey(getResources().getString(R.string.intent_extra_message))) {
message = extras.getString(getResources().getString(R.string.intent_extra_message));
}
}
txtMessage.setText(message);
btnOK.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertActivity.this.finish();
}
});
}
@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
return true;
}
}

View File

@ -1,446 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.proxy.interfaces.APIResultCallBack;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import org.wso2.mdm.agent.services.LocalNotification;
import org.wso2.mdm.agent.services.AgentDeviceAdminReceiver;
import org.wso2.mdm.agent.utils.CommonDialogUtils;
import org.wso2.mdm.agent.utils.Constants;
import org.wso2.mdm.agent.utils.Preference;
import org.wso2.mdm.agent.utils.CommonUtils;
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.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
public class AlreadyRegisteredActivity extends SherlockActivity implements APIResultCallBack {
private static final String TAG = AlreadyRegisteredActivity.class.getSimpleName();
private static final int ACTIVATION_REQUEST = 47;
private String regId;
private Context context;
private Resources resources;
private ProgressDialog progressDialog;
private Button btnUnregister;
private TextView txtRegText;
private static final int TAG_BTN_UNREGISTER = 0;
private static final int TAG_BTN_RE_REGISTER = 2;
private boolean freshRegFlag = false;
private boolean isUnregisterBtnClicked = false;
private AlertDialog.Builder alertDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_already_registered);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(R.layout.custom_sherlock_bar);
getSupportActionBar().setTitle(R.string.empty_app_title);
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName cdmDeviceAdmin = new ComponentName(this, AgentDeviceAdminReceiver.class);
context = this;
resources = context.getResources();
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.
containsKey(getResources().getString(R.string.intent_extra_fresh_reg_flag))) {
freshRegFlag = extras.getBoolean(
getResources().getString(R.string.intent_extra_fresh_reg_flag));
}
}
String registrationId =
Preference.getString(context, resources.
getString(R.string.shared_pref_regId));
if (!registrationId.isEmpty()) {
regId = registrationId;
}
if (freshRegFlag) {
Preference.putString(context, resources.getString(R.string.shared_pref_registered),
resources.getString(R.string.shared_pref_reg_success));
if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) {
startDeviceAdminPrompt(cdmDeviceAdmin);
}
freshRegFlag = false;
}
txtRegText = (TextView) findViewById(R.id.txtRegText);
btnUnregister = (Button) findViewById(R.id.btnUnreg);
btnUnregister.setTag(TAG_BTN_UNREGISTER);
btnUnregister.setOnClickListener(onClickListenerButtonClicked);
LocalNotification.startPolling(context);
}
private 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:
startUnRegistration();
break;
}
}
};
private OnClickListener onClickListenerButtonClicked = new OnClickListener() {
@Override
public void onClick(View view) {
int iTag = (Integer) view.getTag();
switch (iTag) {
case TAG_BTN_UNREGISTER:
showUnregisterDialog();
break;
case TAG_BTN_RE_REGISTER:
loadServerDetailsActivity();
break;
default:
break;
}
}
};
private DialogInterface.OnClickListener isRegisteredFailedOKBtnClickListerner =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
loadServerDetailsActivity();
}
};
/**
* Send unregistration request.
*/
private void startUnRegistration() {
final Context context = AlreadyRegisteredActivity.this;
isUnregisterBtnClicked = true;
progressDialog =
ProgressDialog.show(AlreadyRegisteredActivity.this,
getResources().getString(R.string.dialog_message_unregistering),
getResources().getString(R.string.dialog_message_please_wait),
true);
regId =
Preference.getString(context,
context.getResources().getString(R.string.shared_pref_regId));
JSONObject requestParams = new JSONObject();
try {
requestParams.put(resources.getString(R.string.shared_pref_regId), regId);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON." + e);
}
if (CommonUtils.isNetworkAvailable(context)) {
CommonUtils.callSecuredAPI(AlreadyRegisteredActivity.this,
Constants.UNREGISTER_ENDPOINT, HTTP_METHODS.POST,
requestParams, AlreadyRegisteredActivity.this,
Constants.UNREGISTER_REQUEST_CODE);
} else {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.showNetworkUnavailableMessage(AlreadyRegisteredActivity.this);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (Constants.DEBUG_MODE_ENABLED) {
getSupportMenuInflater().inflate(R.menu.sherlock_menu_debug, menu);
} else {
getSupportMenuInflater().inflate(R.menu.sherlock_menu, menu);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.info_setting:
loadDeviceInfoActivity();
return true;
case R.id.pin_setting:
loadPinCodeActivity();
return true;
case R.id.ip_setting:
loadServerDetailsActivity();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onBackPressed() {
loadHomeScreen();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
loadHomeScreen();
return true;
} else if (keyCode == KeyEvent.KEYCODE_HOME) {
loadHomeScreen();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onResume() {
super.onResume();
if (!freshRegFlag && !isUnregisterBtnClicked) {
if (CommonUtils.isNetworkAvailable(context)) {
JSONObject requestParams = new JSONObject();
try {
requestParams.put(resources.getString(R.string.shared_pref_regId), regId);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON." + e);
}
CommonUtils.callSecuredAPI(AlreadyRegisteredActivity.this,
Constants.IS_REGISTERED_ENDPOINT, HTTP_METHODS.POST,
requestParams, AlreadyRegisteredActivity.this,
Constants.IS_REGISTERED_REQUEST_CODE);
} else {
CommonDialogUtils.showNetworkUnavailableMessage(AlreadyRegisteredActivity.this);
}
}
}
/**
* Displays an internal server error message to the user.
*/
private void displayInternalServerError() {
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);
alertDialog.show();
}
/**
* Clears application data and displays unregister success message.
*/
private void clearAppData() {
CommonUtils.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),
isRegisteredFailedOKBtnClickListerner);
alertDialog.show();
}
@Override
public void onReceiveAPIResult(Map<String, String> result, int requestCode) {
String responseStatus = null;
if (requestCode == Constants.UNREGISTER_REQUEST_CODE) {
stopProgressDialog();
if (result != null) {
responseStatus = result.get(Constants.STATUS_KEY);
if (responseStatus != null && responseStatus.equals(Constants.REQUEST_SUCCESSFUL)) {
clearAppData();
} else if (responseStatus != null && responseStatus.equals(Constants.INTERNAL_SERVER_ERROR)) {
displayInternalServerError();
} else {
loadAuthenticationErrorActivity();
}
} else {
loadAuthenticationErrorActivity();
}
}
if (requestCode == Constants.IS_REGISTERED_REQUEST_CODE) {
stopProgressDialog();
if (result != null) {
responseStatus = result.get(Constants.STATUS_KEY);
if (responseStatus.equals(Constants.INTERNAL_SERVER_ERROR)) {
displayInternalServerError();
} else if (!responseStatus.equals(Constants.REQUEST_SUCCESSFUL)) {
initiateUnregistration();
}
} else {
clearAppData();
}
}
}
/**
* Load device home screen.
*/
private void loadHomeScreen(){
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
super.onBackPressed();
}
/**
* Initiate unregistration.
*/
private void initiateUnregistration(){
txtRegText.setText(R.string.register_text_view_text_unregister);
btnUnregister.setText(R.string.register_button_text);
btnUnregister.setTag(TAG_BTN_RE_REGISTER);
btnUnregister.setOnClickListener(onClickListenerButtonClicked);
CommonUtils.clearAppData(context);
}
/**
* Start device admin activation request.
* @param cdmDeviceAdmin - Device admin component.
*/
private void startDeviceAdminPrompt(ComponentName cdmDeviceAdmin){
Intent deviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cdmDeviceAdmin);
deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
getResources()
.getString(R.string.device_admin_enable_alert));
startActivityForResult(deviceAdminIntent, ACTIVATION_REQUEST);
}
/**
* Display unregistration confirmation dialog.
*/
private void showUnregisterDialog(){
AlertDialog.Builder builder =
new AlertDialog.Builder(
AlreadyRegisteredActivity.this);
builder.setMessage(getResources().getString(R.string.dialog_unregister))
.setNegativeButton(getResources().getString(R.string.yes),
dialogClickListener)
.setPositiveButton(getResources().getString(R.string.no),
dialogClickListener).show();
}
/**
* Load device info activity.
*/
private void loadDeviceInfoActivity(){
Intent intent =
new Intent(AlreadyRegisteredActivity.this,
DisplayDeviceInfoActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
AlreadyRegisteredActivity.class.getSimpleName());
startActivity(intent);
}
/**
* Load server details activity.
*/
private void loadServerDetailsActivity(){
Preference.putString(context, resources.getString(R.string.shared_pref_ip),
resources.getString(R.string.shared_pref_default_string));
Intent intent = new Intent(
AlreadyRegisteredActivity.this,
ServerDetails.class);
intent.putExtra(getResources().getString(R.string.intent_extra_regid),
regId);
intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
AlreadyRegisteredActivity.class.getSimpleName());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
/**
* Load PIN code activity.
*/
private void loadPinCodeActivity(){
Intent intent =
new Intent(AlreadyRegisteredActivity.this, PinCodeActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
AlreadyRegisteredActivity.class.getSimpleName());
startActivity(intent);
}
/**
* Loads authentication error activity.
*/
private void loadAuthenticationErrorActivity() {
Intent intent =
new Intent(AlreadyRegisteredActivity.this,
AuthenticationErrorActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_regid), regId);
intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
AlreadyRegisteredActivity.class.getSimpleName());
startActivity(intent);
}
private void stopProgressDialog() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}

View File

@ -1,647 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import java.util.Map;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.beans.ServerConfig;
import org.wso2.mdm.agent.proxy.beans.CredentialInfo;
import org.wso2.mdm.agent.proxy.interfaces.APIAccessCallBack;
import org.wso2.mdm.agent.proxy.interfaces.APIResultCallBack;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import org.wso2.mdm.agent.proxy.IdentityProxy;
import org.wso2.mdm.agent.utils.CommonDialogUtils;
import org.wso2.mdm.agent.utils.Constants;
import org.wso2.mdm.agent.utils.Preference;
import org.wso2.mdm.agent.utils.CommonUtils;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
/**
* Activity that captures username, password and device ownership details.
*/
public class AuthenticationActivity extends SherlockActivity implements APIAccessCallBack,
APIResultCallBack {
private Button btnRegister;
private EditText etUsername;
private EditText etDomain;
private EditText etPassword;
private RadioButton radioBYOD;
private String deviceType;
private Context context;
private String username;
private String usernameVal;
private String passwordVal;
private ProgressDialog progressDialog;
private static final String MIME_TYPE = "text/html";
private static final String ENCODING_METHOD = "utf-8";
private static final int DEFAILT_REPEAT_COUNT = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_authentication);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(R.layout.custom_sherlock_bar);
getSupportActionBar().setTitle(R.string.empty_app_title);
context = this;
deviceType = getResources().getString(R.string.device_enroll_type_byod);
etDomain = (EditText) findViewById(R.id.etDomain);
etUsername = (EditText) findViewById(R.id.etUsername);
etPassword = (EditText) findViewById(R.id.etPassword);
radioBYOD = (RadioButton) findViewById(R.id.radioBYOD);
etDomain.setFocusable(true);
etDomain.requestFocus();
btnRegister = (Button) findViewById(R.id.btnRegister);
btnRegister.setOnClickListener(onClickAuthenticate);
btnRegister.setEnabled(false);
btnRegister.setOnClickListener(onClickAuthenticate);
// change button color background till user enters a valid input
btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey));
btnRegister.setTextColor(getResources().getColor(R.color.black));
etUsername.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
enableSubmitIfReady();
}
@Override
public void afterTextChanged(Editable s) {
enableSubmitIfReady();
}
});
etPassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
enableSubmitIfReady();
}
@Override
public void afterTextChanged(Editable s) {
enableSubmitIfReady();
}
});
}
private OnClickListener onClickAuthenticate = new OnClickListener() {
@Override
public void onClick(View view) {
if (etUsername.getText() != null && !etUsername.getText().toString().trim().isEmpty() &&
etPassword.getText() != null && !etPassword.getText().toString().trim().isEmpty()) {
passwordVal = etPassword.getText().toString().trim();
usernameVal = etUsername.getText().toString().trim();
if (etDomain.getText() != null && !etDomain.getText().toString().trim().isEmpty()) {
usernameVal +=
getResources().getString(R.string.intent_extra_at) +
etDomain.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);
}
showAuthenticationDialog();
} else {
if (etUsername.getText() != null &&
!etUsername.getText().toString().trim().isEmpty()) {
Toast.makeText(context,
getResources().getString(R.string.toast_error_password),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context,
getResources().getString(R.string.toast_error_username),
Toast.LENGTH_LONG).show();
}
}
}
};
private DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
startAuthentication();
dialog.dismiss();
break;
case DialogInterface.BUTTON_NEGATIVE:
dialog.dismiss();
break;
}
}
};
/**
* Start authentication process.
*/
private void startAuthentication() {
Preference.putString(context, getResources().getString(R.string.shared_pref_reg_type),
deviceType);
// Check network connection availability before calling the API.
if (CommonUtils.isNetworkAvailable(context)) {
initializeIDPLib(getResources().getString(R.string.client_id),
getResources().getString(R.string.client_secret));
progressDialog =
ProgressDialog.show(context,
getResources().getString(R.string.dialog_authenticate),
getResources().getString(R.string.dialog_message_please_wait),
true);
} else {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.showNetworkUnavailableMessage(context);
}
}
/**
* Initialize the Android IDP SDK by passing credentials,client ID and
* client secret.
*
* @param clientKey client id value to access APIs..
* @param clientSecret client secret value to access APIs.
*/
private void initializeIDPLib(String clientKey, String clientSecret) {
String serverIP =
Preference.getString(AuthenticationActivity.this,
context.getResources()
.getString(R.string.shared_pref_ip)
);
ServerConfig utils = new ServerConfig();
utils.setServerIP(serverIP);
String serverURL = utils.getServerURL() + Constants.OAUTH_ENDPOINT;
if (etDomain.getText() != null && !etDomain.getText().toString().trim().isEmpty()) {
username =
etUsername.getText().toString().trim() +
context.getResources().getString(R.string.intent_extra_at) +
etDomain.getText().toString().trim();
} else {
username = etUsername.getText().toString().trim();
}
Preference.putString(context, context.getResources()
.getString(R.string.shared_pref_client_id), clientKey);
Preference.putString(context, context.getResources()
.getString(R.string.shared_pref_client_secret), clientSecret);
CredentialInfo info = new CredentialInfo();
info.setClientID(clientKey);
info.setClientSecret(clientSecret);
info.setUsername(username);
info.setPassword(passwordVal);
info.setTokenEndPoint(serverURL);
IdentityProxy.getInstance().init(info, AuthenticationActivity.this, this.getApplicationContext());
}
@Override
public void onAPIAccessRecive(String status) {
if (status != null) {
if (status.trim().equals(Constants.REQUEST_SUCCESSFUL)) {
Preference.putString(context,
getResources().getString(R.string.shared_pref_username),
username);
// Check network connection availability before calling the API.
CommonDialogUtils.stopProgressDialog(progressDialog);
if (CommonUtils.isNetworkAvailable(context)) {
getLicense();
} else {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.showNetworkUnavailableMessage(AuthenticationActivity.this);
}
} else if (status.trim().equals(Constants.AUTHENTICATION_FAILED)) {
showAuthenticationError();
} else if (status.trim().equals(Constants.INTERNAL_SERVER_ERROR)) {
showInternalServerErrorMessage();
} else {
showAuthCommonErrorMessage();
}
} else {
showAuthCommonErrorMessage();
}
}
/**
* Initialize get device license agreement. Check if the user has already
* agreed to license agreement
*/
private void getLicense() {
String licenseAgreedResponse =
Preference.getString(context,
getResources().getString(R.string.shared_pref_isagreed));
String type =
Preference.getString(context,
getResources().getString(R.string.shared_pref_reg_type));
if (type.trim().equals(getResources().getString(R.string.device_enroll_type_byod))) {
if (licenseAgreedResponse == null) {
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 (CommonUtils.isNetworkAvailable(context)) {
getLicenseFromServer();
} else {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.showNetworkUnavailableMessage(context);
}
} else {
loadPincodeAcitvity();
}
} else {
loadPincodeAcitvity();
}
}
/**
* Retriever license agreement details from the server.
*/
private void getLicenseFromServer() {
String ipSaved =
Preference.getString(context.getApplicationContext(),
context.getResources()
.getString(R.string.shared_pref_ip)
);
ServerConfig utils = new ServerConfig();
utils.setServerIP(ipSaved);
CommonUtils.callSecuredAPI(AuthenticationActivity.this, utils.getAPIServerURL() +
Constants.LICENSE_ENDPOINT,
HTTP_METHODS.GET, null, AuthenticationActivity.this,
Constants.LICENSE_REQUEST_CODE
);
}
@Override
public void onReceiveAPIResult(Map<String, String> result, int requestCode) {
if (requestCode == Constants.LICENSE_REQUEST_CODE) {
manipulateLicenseResponse(result);
}
}
/**
* Manipulates the License agreement response received from server.
*
* @param result the result of the license agreement request
*/
private void manipulateLicenseResponse(Map<String, String> result) {
String responseStatus;
CommonDialogUtils.stopProgressDialog(progressDialog);
if (result != null) {
responseStatus = result.get(Constants.STATUS_KEY);
if (responseStatus.equals(Constants.REQUEST_SUCCESSFUL)) {
String licenseAgreement = result.get(Constants.RESPONSE);
if (licenseAgreement != null) {
Preference.putString(context,
getResources().getString(R.string.shared_pref_eula),
licenseAgreement);
showAgreement(licenseAgreement, Constants.EULA_TITLE);
} else {
showErrorMessage(
getResources().getString(R.string.error_enrollment_failed_detail),
getResources().getString(R.string.error_enrollment_failed));
}
} else if (responseStatus.equals(Constants.INTERNAL_SERVER_ERROR)) {
showInternalServerErrorMessage();
} else {
showEnrollementFailedErrorMessage();
}
} else {
showEnrollementFailedErrorMessage();
}
}
private void showAuthenticationDialog(){
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append(getResources().getString(R.string.dialog_init_middle));
messageBuilder.append(getResources().getString(R.string.intent_extra_space));
messageBuilder.append(deviceType);
messageBuilder.append(getResources().getString(R.string.intent_extra_space));
messageBuilder.append(getResources().getString(R.string.dialog_init_end));
AlertDialog.Builder alertDialog =
CommonDialogUtils.getAlertDialogWithTwoButtonAndTitle(context,
getResources().getString(R.string.dialog_init_device_type),
messageBuilder.toString(),
getResources().getString(R.string.yes),
getResources().getString(R.string.no),
dialogClickListener, dialogClickListener);
alertDialog.show();
}
private void showErrorMessage(String message, String title) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message);
builder.setTitle(title);
builder.setCancelable(true);
builder.setPositiveButton(getResources().getString(R.string.button_ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
cancelEntry();
dialog.dismiss();
}
}
);
AlertDialog alert = builder.create();
alert.show();
}
/**
* Show the license text retrieved from the server.
*
* @param message Message text to be shown as the license.
* @param title Title of the license.
*/
private void showAgreement(String message, String title) {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom_terms_popup);
dialog.setTitle(Constants.EULA_TITLE);
dialog.setCancelable(false);
WebView webView = (WebView) dialog.findViewById(R.id.webview);
webView.loadDataWithBaseURL(null, message, MIME_TYPE, ENCODING_METHOD, null);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
Button cancelButton = (Button) dialog.findViewById(R.id.dialogButtonCancel);
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Preference.putString(context,
getResources().getString(R.string.shared_pref_isagreed),
getResources().getString(R.string.shared_pref_reg_success));
dialog.dismiss();
loadPincodeAcitvity();
}
});
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
cancelEntry();
}
});
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SEARCH &&
event.getRepeatCount() == DEFAILT_REPEAT_COUNT) {
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK &&
event.getRepeatCount() == DEFAILT_REPEAT_COUNT) {
return true;
}
return false;
}
});
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);
}
private void cancelEntry() {
Preference.putString(context, getResources().getString(R.string.shared_pref_policy),
getResources().getString(R.string.shared_pref_default_string));
Preference.putString(context, getResources().getString(R.string.shared_pref_isagreed),
getResources().getString(R.string.shared_pref_reg_fail));
Preference.putString(context, getResources().getString(R.string.shared_pref_registered),
getResources().getString(R.string.shared_pref_reg_fail));
Preference.putString(context, getResources().getString(R.string.shared_pref_ip),
getResources().getString(R.string.shared_pref_default_string));
Intent intentIP = new Intent(AuthenticationActivity.this, ServerDetails.class);
intentIP.putExtra(getResources().getString(R.string.intent_extra_from_activity),
AuthenticationActivity.class.getSimpleName());
intentIP.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intentIP);
}
/**
* Validation done to see if the username and password fields are properly
* entered.
*/
private void enableSubmitIfReady() {
boolean isReady = false;
if (etUsername.getText().toString().length() >= 1 &&
etPassword.getText().toString().length() >= 1) {
isReady = true;
}
if (isReady) {
btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_orange));
btnRegister.setTextColor(getResources().getColor(R.color.white));
btnRegister.setEnabled(true);
} else {
btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey));
btnRegister.setTextColor(getResources().getColor(R.color.black));
btnRegister.setEnabled(false);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.auth_sherlock_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.ip_setting:
Preference.putString(context, getResources().getString(R.string.shared_pref_ip),
getResources().getString(R.string.shared_pref_default_string));
Intent intentIP = new Intent(AuthenticationActivity.this, ServerDetails.class);
intentIP.putExtra(getResources().getString(R.string.intent_extra_from_activity),
AuthenticationActivity.class.getSimpleName());
startActivity(intentIP);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@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);
return true;
} else if (keyCode == KeyEvent.KEYCODE_HOME) {
this.finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
private DialogInterface.OnClickListener senderIdFailedClickListener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
etUsername.setText(Constants.EMPTY_STRING);
etPassword.setText(Constants.EMPTY_STRING);
etDomain.setText(Constants.EMPTY_STRING);
btnRegister.setEnabled(false);
btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey));
btnRegister.setTextColor(getResources().getColor(R.color.black));
}
};
/**
* Shows enrollment failed error.
*/
private void showEnrollementFailedErrorMessage() {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(
R.string.error_enrollment_failed),
getResources().getString(
R.string.error_enrollment_failed_detail),
getResources().getString(
R.string.button_ok),
senderIdFailedClickListener);
}
/**
* Shows internal server error message for authentication.
*/
private void showInternalServerErrorMessage() {
CommonDialogUtils.stopProgressDialog(progressDialog);
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);
}
/**
* Shows credentials error message for authentication.
*/
private void showAuthenticationError(){
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(R.string.title_head_authentication_error),
getResources().getString(R.string.error_authentication_failed),
getResources().getString(R.string.button_ok),
null);
}
/**
* Shows common error message for authentication.
*/
private void showAuthCommonErrorMessage() {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context,
getResources().getString(
R.string.title_head_authentication_error),
getResources().getString(
R.string.error_for_all_unknown_authentication_failures),
getResources().getString(
R.string.button_ok),
null);
}
}

View File

@ -1,132 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
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 com.google.android.gcm.GCMRegistrar;
import org.wso2.mdm.agent.R;
public class AuthenticationErrorActivity extends Activity {
private String registrationId;
private Button btnTryAgain;
private static final int TAG_BTN_TRY_AGAIN = 0;
private static final int TAG_BTN_UNREGISTER = 1;
private String fromActivity;
private TextView txtMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_authentication_error);
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey(getResources().getString(R.string.intent_extra_regid))) {
registrationId =
extras.getString(getResources().getString(R.string.intent_extra_regid));
}
if (extras.containsKey(getResources().getString(R.string.intent_extra_from_activity))) {
fromActivity =
extras.getString(
getResources().getString(R.string.intent_extra_from_activity));
}
}
if (registrationId == null || registrationId.isEmpty()) {
registrationId = GCMRegistrar.getRegistrationId(this);
}
txtMessage = (TextView) findViewById(R.id.error);
btnTryAgain = (Button) findViewById(R.id.btnTryAgain);
btnTryAgain.setTag(TAG_BTN_TRY_AGAIN);
btnTryAgain.setOnClickListener(onClickListener_BUTTON_CLICKED);
if (fromActivity.equals(RegistrationActivity.class.getSimpleName())) {
txtMessage.setText(getResources().getString(R.string.error_registration_failed));
} else if (fromActivity.equals(AlreadyRegisteredActivity.class.getSimpleName())) {
txtMessage.setText(getResources().getString(R.string.error_unregistration_failed));
btnTryAgain.setTag(TAG_BTN_UNREGISTER);
}
}
OnClickListener onClickListener_BUTTON_CLICKED = new OnClickListener() {
@Override
public void onClick(View view) {
int tag = (Integer) view.getTag();
switch (tag) {
case TAG_BTN_TRY_AGAIN:
tryAgain();
break;
case TAG_BTN_UNREGISTER:
finish();
break;
default:
tryAgain();
break;
}
}
};
/**
* Retry authentication.
*/
private void tryAgain() {
Intent intent = new Intent(AuthenticationErrorActivity.this, AuthenticationActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
AuthenticationActivity.class.getSimpleName());
intent.putExtra(getResources().getString(R.string.intent_extra_regid), registrationId);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.authentication_error, menu);
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
tryAgain();
return true;
} else if (keyCode == KeyEvent.KEYCODE_HOME) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}

View File

@ -1,144 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.api.DeviceInfo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class DisplayDeviceInfoActivity extends Activity {
private String fromActivity;
private String registrationId;
private TextView deviceId;
private TextView deviceName;
private TextView model;
private TextView operator;
private TextView sdk;
private TextView os;
private TextView root;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_device_info);
DeviceInfo deviceInfo = new DeviceInfo(this.getApplicationContext());
deviceId = (TextView) findViewById(R.id.txtId);
deviceName = (TextView) findViewById(R.id.txtDevice);
model = (TextView) findViewById(R.id.txtModel);
operator = (TextView) findViewById(R.id.txtOperator);
sdk = (TextView) findViewById(R.id.txtSDK);
os = (TextView) findViewById(R.id.txtOS);
root = (TextView) findViewById(R.id.txtRoot);
deviceId.setText(getResources().getString(R.string.info_label_imei) +
getResources().getString(R.string.intent_extra_space) +
deviceInfo.getDeviceId());
deviceName.setText(getResources().getString(R.string.info_label_device) +
getResources().getString(R.string.intent_extra_space) +
deviceInfo.getDeviceName());
model.setText(getResources().getString(R.string.info_label_model) +
getResources().getString(R.string.intent_extra_space) +
deviceInfo.getDeviceModel());
String operators = null;
if (deviceInfo.getNetworkOperatorName() != null) {
operators = deviceInfo.getNetworkOperatorName();
}else{
operators = getResources().getString(R.string.info_label_no_sim);
}
operator.setText(getResources().getString(R.string.info_label_operator) +
getResources().getString(R.string.intent_extra_space) + operators);
if (deviceInfo.getIMSINumber() != null) {
sdk.setText(getResources().getString(R.string.info_label_imsi) +
getResources().getString(R.string.intent_extra_space) +
deviceInfo.getIMSINumber());
} else {
sdk.setText(getResources().getString(R.string.info_label_imsi) +
getResources().getString(R.string.intent_extra_space) + operators);
}
os.setText(getResources().getString(R.string.info_label_os) +
getResources().getString(R.string.intent_extra_space) +
deviceInfo.getOsVersion());
root.setText(getResources().getString(R.string.info_label_rooted) +
getResources().getString(R.string.intent_extra_space) +
(deviceInfo.isRooted() ? getResources().getString(R.string.yes)
: getResources().getString(R.string.no)));
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));
}
if (extras.containsKey(getResources().getString(R.string.intent_extra_regid))) {
registrationId =
extras.getString(getResources().getString(R.string.intent_extra_regid));
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
public boolean onOptionsItemSelected(MenuItem menu) {
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null &&
fromActivity.equals(AlreadyRegisteredActivity.class.getSimpleName())) {
Intent intent =
new Intent(DisplayDeviceInfoActivity.this,
AlreadyRegisteredActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
DisplayDeviceInfoActivity.class.getSimpleName());
intent.putExtra(getResources().getString(R.string.intent_extra_regid), registrationId);
startActivity(intent);
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);
}
}

View File

@ -1,98 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import java.util.Locale;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.services.MessageProcessor;
import org.wso2.mdm.agent.utils.Constants;
import org.wso2.mdm.agent.utils.Preference;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.google.android.gcm.GCMBaseIntentService;
/**
* IntentService responsible for handling GCM messages.
*/
public class GCMIntentService extends GCMBaseIntentService {
private static final String MESSAGE_MODE = "GCM";
private static final String TAG = "GCMIntentService";
public GCMIntentService() {
super(Constants.SENDER_ID);
}
@Override
protected void onRegistered(Context context, String registrationId) {
if (Constants.DEBUG_MODE_ENABLED) {
Log.i(TAG, "Device registered." + registrationId);
}
Preference.putString(context, getResources().getString(R.string.shared_pref_regId),
registrationId);
}
@Override
protected void onUnregistered(Context context, String registrationId) {
if (Constants.DEBUG_MODE_ENABLED) {
Log.i(TAG, "Device unregistered.");
}
}
@Override
protected void onMessage(Context context, Intent intent) {
String mode =
Preference.getString(context,
context.getResources()
.getString(R.string.shared_pref_message_mode)
);
if (mode.trim().toUpperCase(Locale.getDefault()).equals(MESSAGE_MODE)) {
MessageProcessor msg = new MessageProcessor(context);
msg.getMessages();
}
}
@Override
protected void onDeletedMessages(Context context, int total) {
if (Constants.DEBUG_MODE_ENABLED) {
Log.i(TAG, "Received deleted messages notification.");
}
}
@Override
public void onError(Context context, String errorId) {
if (Constants.DEBUG_MODE_ENABLED) {
Log.i(TAG, "Received error." + errorId);
}
}
@Override
protected boolean onRecoverableError(Context context, String errorId) {
if (Constants.DEBUG_MODE_ENABLED) {
Log.i(TAG, "Received recoverable error." + errorId);
}
return super.onRecoverableError(context, errorId);
}
}

View File

@ -1,66 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.widget.TextView;
import org.wso2.mdm.agent.R;
public class NotifyActivity extends Activity {
private TextView txtNotify;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notify);
txtNotify = (TextView) findViewById(R.id.notify);
Intent intent = getIntent();
String notification =
intent.getStringExtra(getResources().getString(R.string.intent_extra_notification));
txtNotify.setText(notification);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.notify, menu);
return true;
}
@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);
this.finish();
return true;
} else if (keyCode == KeyEvent.KEYCODE_HOME) {
this.finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}

View File

@ -1,326 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.utils.CommonDialogUtils;
import org.wso2.mdm.agent.utils.Preference;
public class PinCodeActivity extends Activity {
private TextView txtPin;
private EditText evPin;
private EditText evOldPin;
private Button btnPin;
private String username;
private String registrationId;
private static final int TAG_BTN_SET_PIN = 0;
private static final int PIN_MIN_LENGTH = 4;
private String fromActivity;
private Context context;
private AlertDialog.Builder alertDialog;
private EditText evInput;
@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))) {
username =
extras.getString(getResources().getString(R.string.intent_extra_username));
}
if (extras.containsKey(getResources().getString(R.string.intent_extra_regid))) {
registrationId =
extras.getString(getResources().getString(R.string.intent_extra_regid));
}
if (extras.containsKey(getResources().getString(R.string.intent_extra_from_activity))) {
fromActivity =
extras.getString(
getResources().getString(R.string.intent_extra_from_activity));
}
}
txtPin = (TextView) findViewById(R.id.lblPin);
evPin = (EditText) findViewById(R.id.txtPinCode);
evOldPin = (EditText) findViewById(R.id.txtOldPinCode);
btnPin = (Button) findViewById(R.id.btnSetPin);
btnPin.setTag(TAG_BTN_SET_PIN);
btnPin.setOnClickListener(onClickListenerButtonClicked);
btnPin.setEnabled(false);
btnPin.setBackground(getResources().getDrawable(R.drawable.btn_grey));
btnPin.setTextColor(getResources().getColor(R.color.black));
if (fromActivity != null &&
fromActivity.equals(AlreadyRegisteredActivity.class.getSimpleName())) {
txtPin.setVisibility(View.GONE);
evOldPin.setVisibility(View.VISIBLE);
evPin.setHint(getResources().getString(R.string.hint_new_pin));
evPin.setEnabled(true);
evPin.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
enableNewPINSubmitIfReady();
}
@Override
public void afterTextChanged(Editable s) {
enableSubmitIfReady();
}
});
evOldPin.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
enableNewPINSubmitIfReady();
}
@Override
public void afterTextChanged(Editable s) {
enableSubmitIfReady();
}
});
} else {
evPin.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
enableSubmitIfReady();
}
@Override
public void afterTextChanged(Editable s) {
enableSubmitIfReady();
}
});
}
}
private OnClickListener onClickListenerButtonClicked = new OnClickListener() {
@Override
public void onClick(View view) {
int viewTag = (Integer) view.getTag();
switch (viewTag) {
case TAG_BTN_SET_PIN:
setPINCode();
break;
default:
break;
}
}
};
private void setPINCode(){
evInput = new EditText(PinCodeActivity.this);
alertDialog =
CommonDialogUtils
.getAlertDialogWithTwoButtonAndEditView(PinCodeActivity.this,
getResources()
.getString(
R.string.title_head_confirm_pin),
getResources()
.getString(
R.string.button_ok),
getResources()
.getString(
R.string.button_cancel),
dialogClickListener,
dialogClickListener,
evInput);
final AlertDialog dialog = alertDialog.create();
dialog.show();
// Overriding default positive button behavior to keep the
// dialog open, if PINS don't match.
dialog.getButton(AlertDialog.BUTTON_POSITIVE)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (evPin.getText().toString()
.equals(evInput.getText().toString())) {
savePin();
dialog.dismiss();
} else {
evInput.setError(getResources().getString(
R.string.validation_pin_confirm));
}
}
});
evInput.setInputType(InputType.TYPE_CLASS_NUMBER);
evInput.setTransformationMethod(new PasswordTransformationMethod());
}
private DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
savePin();
break;
case DialogInterface.BUTTON_NEGATIVE:
dialog.dismiss();
break;
}
}
};
private void savePin() {
Preference.putString(context, getResources().getString(R.string.shared_pref_pin),
evPin.getText().toString().trim());
if (fromActivity != null &&
(fromActivity.equals(AlreadyRegisteredActivity.class.getSimpleName()))) {
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.toast_message_pin_change_success),
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(PinCodeActivity.this, AlreadyRegisteredActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
PinCodeActivity.class.getSimpleName());
intent.putExtra(getResources().getString(R.string.intent_extra_regid), registrationId);
startActivity(intent);
} else {
Intent intent = new Intent(PinCodeActivity.this, RegistrationActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_regid), registrationId);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(getResources().getString(R.string.intent_extra_username), username);
startActivity(intent);
}
}
private void enableSubmitIfReady() {
boolean isReady = false;
if (evPin.getText().toString().length() >= PIN_MIN_LENGTH) {
isReady = true;
}
if (isReady) {
btnPin.setBackground(getResources().getDrawable(R.drawable.btn_orange));
btnPin.setTextColor(getResources().getColor(R.color.white));
btnPin.setEnabled(true);
} else {
btnPin.setBackground(getResources().getDrawable(R.drawable.btn_grey));
btnPin.setTextColor(getResources().getColor(R.color.black));
btnPin.setEnabled(false);
}
}
private void enableNewPINSubmitIfReady() {
boolean isReady = false;
String pin =
Preference.getString(context,
getResources().getString(R.string.shared_pref_pin));
if (evOldPin.getText().toString().trim().length() >= PIN_MIN_LENGTH &&
evOldPin.getText().toString().trim().equals(pin.trim())) {
evPin.setEnabled(true);
} else {
evPin.setEnabled(false);
}
if (evPin.getText().toString().trim().length() >= PIN_MIN_LENGTH &&
evOldPin.getText().toString().trim().length() >= PIN_MIN_LENGTH) {
if (evOldPin.getText().toString().trim().equals(pin.trim())) {
isReady = true;
} else {
isReady = false;
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.toast_message_pin_change_failed),
Toast.LENGTH_SHORT).show();
}
}
if (isReady) {
btnPin.setBackground(getResources().getDrawable(R.drawable.btn_orange));
btnPin.setTextColor(getResources().getColor(R.color.white));
btnPin.setEnabled(true);
} else {
btnPin.setBackground(getResources().getDrawable(R.drawable.btn_grey));
btnPin.setTextColor(getResources().getColor(R.color.black));
btnPin.setEnabled(false);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && fromActivity != null &&
fromActivity.equals(AlreadyRegisteredActivity.class.getSimpleName())) {
Intent intent = new Intent(PinCodeActivity.this, AlreadyRegisteredActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_from_activity),
PinCodeActivity.class.getSimpleName());
intent.putExtra(getResources().getString(R.string.intent_extra_regid), registrationId);
startActivity(intent);
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) {
return true;
}
}

View File

@ -1,202 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import java.util.Map;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.beans.ServerConfig;
import org.wso2.mdm.agent.proxy.interfaces.APIResultCallBack;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import org.wso2.mdm.agent.services.BuildDeviceInfoPayload;
import org.wso2.mdm.agent.utils.CommonDialogUtils;
import org.wso2.mdm.agent.utils.Constants;
import org.wso2.mdm.agent.utils.Preference;
import org.wso2.mdm.agent.utils.CommonUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
public class RegistrationActivity extends Activity implements APIResultCallBack {
private Context context;
private ProgressDialog progressDialog;
private AlertDialog.Builder alertDialog;
private BuildDeviceInfoPayload deviceInfoBuilder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
deviceInfoBuilder = new BuildDeviceInfoPayload(context);
registerDevice();
}
private void registerDevice() {
progressDialog =
CommonDialogUtils.showPrgressDialog(RegistrationActivity.this,
getResources()
.getString(R.string.dialog_enrolling),
getResources()
.getString(R.string.dialog_please_wait),
null);
progressDialog.show();
String type =
Preference.getString(context,
context.getResources()
.getString(R.string.shared_pref_reg_type)
);
String username =
Preference.getString(context,
context.getResources().getString(R.string.username));
deviceInfoBuilder.build(type, username);
// Check network connection availability before calling the API.
if (CommonUtils.isNetworkAvailable(context)) {
// Call device registration API.
String ipSaved =
Preference.getString(context.getApplicationContext(),
context.getResources()
.getString(R.string.shared_pref_ip)
);
ServerConfig utils = new ServerConfig();
utils.setServerIP(ipSaved);
CommonUtils.callSecuredAPI(RegistrationActivity.this, utils.getAPIServerURL() +
Constants.REGISTER_ENDPOINT,
HTTP_METHODS.POST, deviceInfoBuilder.getDeviceInfoPayload(),
RegistrationActivity.this,
Constants.REGISTER_REQUEST_CODE
);
} else {
CommonDialogUtils.stopProgressDialog(progressDialog);
CommonDialogUtils.showNetworkUnavailableMessage(RegistrationActivity.this);
}
}
@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);
}
private DialogInterface.OnClickListener registrationFailedOKBtnClickListerner =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
loadAuthenticationErrorActivity();
}
};
/**
* Loads Already registered activity.
*/
private void loadAlreadyRegisteredActivity(){
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);
}
/**
* Display connectivity error.
*/
private void displayConnectionError(){
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();
}
/**
* Display internal server error.
*/
private void displayInternalServerError(){
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);
}
@Override
public void onReceiveAPIResult(Map<String, String> result, int requestCode) {
CommonDialogUtils.stopProgressDialog(progressDialog);
String responseStatus = null;
if (result != null) {
responseStatus = result.get(Constants.STATUS_KEY);
if (responseStatus.equals(Constants.REQUEST_SUCCESSFUL)) {
loadAlreadyRegisteredActivity();
} else {
displayInternalServerError();
}
} else {
displayConnectionError();
}
}
/**
* Loads Authentication error activity.
*/
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.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}

View File

@ -1,165 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.api.DeviceInfo;
import org.wso2.mdm.agent.factory.DeviceStateFactory;
import org.wso2.mdm.agent.interfaces.DeviceState;
import org.wso2.mdm.agent.utils.Preference;
import org.wso2.mdm.agent.utils.Response;
/**
* This the the activity that is used to capture the server's host name.
*/
public class ServerDetails extends Activity {
private TextView evServerIP;
private Button btnStartRegistration;
private Context context;
private DeviceInfo deviceInfo;
private DeviceState state;
private TextView txtSeverAddress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
context = this.getApplicationContext();
deviceInfo = new DeviceInfo(context);
state = DeviceStateFactory.getDeviceState(context, deviceInfo.getSdkVersion());
evServerIP = (TextView) findViewById(R.id.evServerIP);
txtSeverAddress = (TextView) findViewById(R.id.tvSeverAddress);
btnStartRegistration = (Button) findViewById(R.id.btnStartRegistration);
Response compatibility = state.evaluateCompatibility();
if (!compatibility.getCode()) {
btnStartRegistration.setVisibility(View.GONE);
txtSeverAddress.setVisibility(View.GONE);
evServerIP.setVisibility(View.GONE);
} else {
btnStartRegistration.setVisibility(View.VISIBLE);
evServerIP.setVisibility(View.VISIBLE);
String ipSaved =
Preference.getString(context.getApplicationContext(),
getResources().getString(R.string.shared_pref_ip));
// check if we have the IP saved previously.
if (ipSaved != null && !ipSaved.isEmpty()) {
evServerIP.setText(ipSaved);
startAuthenticationActivity();
} else {
evServerIP.setText(ipSaved);
}
String deviceActive =
Preference.getString(context,
context.getResources()
.getString(R.string.shared_pref_device_active)
);
if (deviceActive != null &&
deviceActive.equals(context.getResources()
.getString(R.string.shared_pref_reg_success))) {
Intent intent = new Intent(ServerDetails.this, AlreadyRegisteredActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
// on click handler for start registration.
btnStartRegistration.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
loadStartRegistrationDialog();
}
});
}
}
private void loadStartRegistrationDialog(){
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(ServerDetails.this);
StringBuilder messageBuilder = new StringBuilder();
messageBuilder
.append(getResources().getString(R.string.dialog_init_confirmation));
messageBuilder.append(context.getResources()
.getString(R.string.intent_extra_space));
messageBuilder.append(evServerIP.getText().toString());
messageBuilder.append(context.getResources()
.getString(R.string.intent_extra_space));
messageBuilder
.append(getResources().getString(R.string.dialog_init_end_general));
alertBuilder.setMessage(messageBuilder.toString())
.setPositiveButton(getResources().getString(R.string.yes),
dialogClickListener)
.setNegativeButton(getResources().getString(R.string.no),
dialogClickListener).show();
}
private DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
if (!evServerIP.getText().toString().trim().isEmpty()) {
Preference.putString(context.getApplicationContext(),
getResources()
.getString(R.string.shared_pref_ip),
evServerIP.getText().toString().trim());
startAuthenticationActivity();
} else {
Toast.makeText(context.getApplicationContext(),
getResources().getString(
R.string.toast_message_enter_server_address),
Toast.LENGTH_LONG).show();
}
break;
case DialogInterface.BUTTON_NEGATIVE:
dialog.dismiss();
break;
}
}
};
/**
* This method is called to open AuthenticationActivity.
*/
private void startAuthenticationActivity() {
Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
@Override
protected void onDestroy() {
context = null;
super.onDestroy();
}
}

View File

@ -1,240 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.api;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.beans.DeviceAppInfo;
import org.wso2.mdm.agent.utils.StreamHandler;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.provider.Browser;
import android.util.Base64;
import android.util.Log;
public class ApplicationManager {
private Context context;
private static final int SYSTEM_APPS_DISABLED_FLAG = 0;
private static final int MAX_URL_HASH = 32;
private static final int COMPRESSION_LEVEL = 100;
private static final int BUFFER_SIZE = 1024;
private static final int READ_FAILED = -1;
private static final int BUFFER_OFFSET = 0;
private static final String TAG = ApplicationManager.class.getName();
private Resources resources;
private PackageManager packageManager;
public ApplicationManager(Context context) {
this.context = context;
this.resources = context.getResources();
this.packageManager = context.getPackageManager();
}
/**
* Returns a list of all the applications installed on the device.
* @return - List of applications which installed on the device.
*/
public ArrayList<DeviceAppInfo> getInstalledApps() {
ArrayList<DeviceAppInfo> appList = new ArrayList<DeviceAppInfo>();
DeviceAppInfo app;
List<PackageInfo> packages = packageManager.
getInstalledPackages(SYSTEM_APPS_DISABLED_FLAG);
for (PackageInfo packageInfo : packages) {
app = new DeviceAppInfo();
app.setAppname(packageInfo.applicationInfo.
loadLabel(packageManager).toString());
app.setPackagename(packageInfo.packageName);
app.setVersionName(packageInfo.versionName);
app.setVersionCode(packageInfo.versionCode);
appList.add(app);
}
return appList;
}
/**
* Returns the app name for a particular package name.
* @param packageName - Package name which you need the app name.
* @return - Application name.
*/
public String getAppNameFromPackage(String packageName) {
String appName = null;
List<PackageInfo> packages = packageManager.
getInstalledPackages(SYSTEM_APPS_DISABLED_FLAG);
for (PackageInfo packageInfo : packages) {
if (packageName != null && packageName.equals(packageInfo.packageName)) {
appName = packageInfo.applicationInfo.
loadLabel(packageManager).toString();
break;
}
}
return appName;
}
/**
* Returns a base64 encoded string for a particular image.
* @param drawable - Image as a Drawable object.
* @return - Base64 encoded value of the drawable.
*/
public String encodeImage(Drawable drawable) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, COMPRESSION_LEVEL, outStream);
byte[] bitmapContent = outStream.toByteArray();
String encodedImage = Base64.encodeToString(bitmapContent, Base64.NO_WRAP);
StreamHandler.closeOutputStream(outStream, TAG);
return encodedImage;
}
/**
* Installs an application to the device.
* @param url - APK Url should be passed in as a String.
*/
public void installApp(String url) {
AppUpdater updator = new AppUpdater();
updator.setContext(context);
updator.execute(url);
}
/**
* Removes an application from the device.
* @param packageName - Application package name should be passed in as a String.
*/
public void uninstallApplication(String packageName) {
if (packageName != null &&
!packageName.contains(resources.getString(R.string.application_package_prefix))) {
packageName = resources.getString(R.string.application_package_prefix) + packageName;
}
Uri packageURI = Uri.parse(packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
uninstallIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(uninstallIntent);
}
/**
* Creates a webclip on the device home screen.
* @param url - URL should be passed in as a String.
* @param title - Title(Web app title) should be passed in as a String.
*/
public void createWebAppBookmark(String url, String title) {
final Intent bookmarkIntent = new Intent();
final Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
long urlHash = url.hashCode();
long uniqueId = (urlHash << MAX_URL_HASH) | actionIntent.hashCode();
actionIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context,
R.drawable.ic_bookmark)
);
bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_action));
context.sendBroadcast(bookmarkIntent);
}
/**
* Installs or updates an application to the device.
* @param url - APK Url should be passed in as a String.
*/
public class AppUpdater extends AsyncTask<String, Void, Void> {
private Context context;
public void setContext(Context context) {
this.context = context;
}
@Override
protected Void doInBackground(String... inputData) {
FileOutputStream outStream=null;
InputStream inStream=null;
try {
URL url = new URL(inputData[BUFFER_OFFSET]);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection
.setRequestMethod(resources.getString(R.string.server_util_req_type_get));
urlConnection.setDoOutput(true);
urlConnection.connect();
String directory = Environment.getExternalStorageDirectory().getPath() +
resources.getString(R.string.application_mgr_download_location);
File file = new File(directory);
file.mkdirs();
File outputFile = new File(file,
resources.getString(R.string.application_mgr_download_file_name));
if (outputFile.exists()) {
outputFile.delete();
}
outStream = new FileOutputStream(outputFile);
inStream = urlConnection.getInputStream();
byte[] buffer = new byte[BUFFER_SIZE];
int lengthFile;
while ((lengthFile = inStream.read(buffer)) != READ_FAILED) {
outStream.write(buffer, BUFFER_OFFSET, lengthFile);
}
String filePath = directory + resources.getString(R.string.application_mgr_download_file_name);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.fromFile(new File(filePath)),
resources.getString(R.string.application_mgr_mime)
);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (IOException e) {
Log.e("File download/save failure in AppUpdator.", e.getMessage());
} finally {
StreamHandler.closeOutputStream(outStream, TAG);
StreamHandler.closeInputStream(inStream, TAG);
}
return null;
}
};
}

View File

@ -1,164 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.api;
import java.util.List;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.utils.Preference;
import android.content.Context;
import android.content.res.Resources;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
public class DeviceInfo {
private Root rootChecker;
private Context context;
private Resources resources;
private TelephonyManager telephonyManager;
public DeviceInfo(Context context) {
this.context = context;
this.resources = context.getResources();
this.telephonyManager = (TelephonyManager) context.
getSystemService(Context.TELEPHONY_SERVICE);
}
/**
* Returns the network operator name.
* @return - Network operator name.
*/
public String getNetworkOperatorName() {
return telephonyManager.getSimOperatorName();
}
/**
* Returns the device model.
* @return - Device model.
*/
public String getDeviceModel() {
return android.os.Build.MODEL;
}
/**
* Returns the device manufacturer.
* @return - Device manufacturer.
*/
public String getDeviceManufacturer() {
return Build.MANUFACTURER;
}
/**
* Returns the OS version.
* @return - Device OS version.
*/
public String getOsVersion() {
return android.os.Build.VERSION.RELEASE;
}
/**
* Returns the SDK Version number.
* @return - Device android SDK version number.
*/
public int getSdkVersion() {
return android.os.Build.VERSION.SDK_INT;
}
/**
* Returns the device name.
* @return - Device name.
*/
public String getDeviceName() {
return android.os.Build.DEVICE;
}
/**
* Returns the IMEI Number.
* @return - Device IMEI number.
*/
public String getDeviceId() {
String deviceId = telephonyManager.getDeviceId();
if (deviceId == null || deviceId.isEmpty()) {
deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
}
return deviceId;
}
/**
* Returns the IMSI Number.
* @return - Device IMSI number.
*/
public String getIMSINumber() {
return telephonyManager.getSubscriberId();
}
/**
* Returns the device WiFi MAC.
* @return - Device WiFi MAC.
*/
public String getMACAddress() {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
return wInfo.getMacAddress();
}
/**
* Returns the Email address of the device owner.
* @return - Device owner email address.
*/
public String getEmail() {
return Preference.getString(context,
resources.getString(R.string.shared_pref_username));
}
/**
* Returns true if the device is a Rooted device.
* @return - Device rooted status.
*/
public boolean isRooted() {
rootChecker = new Root();
return rootChecker.isDeviceRooted();
}
/**
* Returns the SIM serial number.
* @return - Device SIM serial number.
*/
public String getSimSerialNumber() {
return telephonyManager.getSimSerialNumber();
}
/**
* Returns all the sensors available on the device as a List.
* @return - List of all the sensors available on the device.
*/
public List<Sensor> getAllSensors() {
SensorManager sensorManager =
(SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
return sensorManager.getSensorList(Sensor.TYPE_ALL);
}
}

View File

@ -1,164 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.api;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.wso2.mdm.agent.interfaces.DeviceState;
import org.wso2.mdm.agent.utils.Response;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Environment;
import android.os.StatFs;
public class DeviceStateICS implements DeviceState{
private Context context;
private DeviceInfo info;
private File dataDirectory;
private StatFs directoryStatus;
private static final int DEFAULT_LEVEL = -1;
private static final float PRECENTAGE_MULTIPLIER = 100.0f;
private static final int SCALE = 2;
private static final int MEMORY_NOT_AVAILABLE = 0;
private static final double GB_DIVIDER = 1073741824;
private static final double MB_DIVIDER = 1048576;
public DeviceStateICS(Context context) {
this.context = context;
this.info = new DeviceInfo(context);
this.dataDirectory = Environment.getDataDirectory();
this.directoryStatus = new StatFs(dataDirectory.getPath());
}
@Override
public boolean externalMemoryAvailable() {
return android.os.Environment.getExternalStorageState()
.equals(android.os.Environment.MEDIA_MOUNTED);
}
@SuppressWarnings("deprecation")
@Override
public double getAvailableInternalMemorySize() {
double blockSize, availableBlocks;
blockSize = directoryStatus.getBlockSize();
availableBlocks = directoryStatus.getAvailableBlocks();
return formatSizeInGb(availableBlocks * blockSize);
}
@SuppressWarnings("deprecation")
@Override
public double getTotalInternalMemorySize() {
double blockSize, totalBlocks;
blockSize = directoryStatus.getBlockSize();
totalBlocks = directoryStatus.getBlockCount();
return formatSizeInGb(totalBlocks * blockSize);
}
@SuppressWarnings("deprecation")
@Override
public double getAvailableExternalMemorySize() {
double blockSize, availableBlocks;
if (externalMemoryAvailable()) {
blockSize = directoryStatus.getBlockSize();
availableBlocks = directoryStatus.getAvailableBlocks();
return formatSizeInGb(availableBlocks * blockSize);
} else {
return MEMORY_NOT_AVAILABLE;
}
}
@SuppressWarnings("deprecation")
@Override
public double getTotalExternalMemorySize() {
double blockSize, totalBlocks;
if (externalMemoryAvailable()) {
blockSize = directoryStatus.getBlockSize();
totalBlocks = directoryStatus.getBlockCount();
return formatSizeInGb(totalBlocks * blockSize);
} else {
return MEMORY_NOT_AVAILABLE;
}
}
@Override
public double formatSizeInGb(double byteValue) {
double gbValue = (byteValue / GB_DIVIDER);
BigDecimal roundedValue = new BigDecimal(gbValue).setScale(SCALE, RoundingMode.HALF_EVEN);
gbValue = roundedValue.doubleValue();
return gbValue;
}
@Override
public double formatSizeInMb(double byteValue) {
double mbValue = (byteValue / MB_DIVIDER);
BigDecimal roundedValue = new BigDecimal(mbValue).setScale(SCALE, RoundingMode.HALF_EVEN);
mbValue = roundedValue.doubleValue();
return mbValue;
}
@Override
public Response evaluateCompatibility() {
if (!(info.getSdkVersion() >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) &&
info.isRooted()) {
return Response.INCOMPATIBLE;
} else if (info.getSdkVersion() < android.os.Build.VERSION_CODES.FROYO) {
return Response.INCOMPATIBLE;
} else if (info.isRooted()) {
return Response.INCOMPATIBLE;
}
return Response.COMPATIBLE;
}
@Override
public String getIpAddress() {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return intToIp(wifiInfo.getIpAddress());
}
@Override
public String intToIp(int ip) {
return (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." +
((ip >> 24) & 0xFF);
}
@Override
public float getBatteryLevel() {
Intent batteryIntent = context.registerReceiver(null,
new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, DEFAULT_LEVEL);
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, DEFAULT_LEVEL);
return ((float) level / (float) scale) * PRECENTAGE_MULTIPLIER;
}
}

View File

@ -1,167 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.api;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.wso2.mdm.agent.interfaces.DeviceState;
import org.wso2.mdm.agent.utils.Response;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
public class DeviceStateJB implements DeviceState{
private Context context;
private DeviceInfo info;
private File dataDirectory;
private StatFs directoryStatus;
private static final int DEFAULT_LEVEL = -1;
private static final float PRECENTAGE_MULTIPLIER = 100.0f;
private static final int SCALE = 2;
private static final int MEMORY_NOT_AVAILABLE = 0;
private static final double GB_DIVIDER = 1073741824;
private static final double MB_DIVIDER = 1048576;
public DeviceStateJB(Context context) {
this.context = context;
this.info = new DeviceInfo(context);
this.dataDirectory = Environment.getDataDirectory();
this.directoryStatus = new StatFs(dataDirectory.getPath());
}
@Override
public boolean externalMemoryAvailable() {
return android.os.Environment.getExternalStorageState()
.equals(android.os.Environment.MEDIA_MOUNTED);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public double getAvailableInternalMemorySize() {
double blockSize, availableBlocks;
blockSize = directoryStatus.getBlockSizeLong();
availableBlocks = directoryStatus.getAvailableBlocksLong();
return formatSizeInGb(availableBlocks * blockSize);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public double getTotalInternalMemorySize() {
double blockSize, totalBlocks;
blockSize = directoryStatus.getBlockSizeLong();
totalBlocks = directoryStatus.getBlockCountLong();
return formatSizeInGb(totalBlocks * blockSize);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public double getAvailableExternalMemorySize() {
double blockSize, availableBlocks;
if (externalMemoryAvailable()) {
blockSize = directoryStatus.getBlockSizeLong();
availableBlocks = directoryStatus.getAvailableBlocksLong();
return formatSizeInGb(availableBlocks * blockSize);
} else {
return MEMORY_NOT_AVAILABLE;
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public double getTotalExternalMemorySize() {
double blockSize, totalBlocks;
if (externalMemoryAvailable()) {
blockSize = directoryStatus.getBlockSizeLong();
totalBlocks = directoryStatus.getBlockCountLong();
return formatSizeInGb(totalBlocks * blockSize);
} else {
return MEMORY_NOT_AVAILABLE;
}
}
@Override
public double formatSizeInGb(double byteValue) {
double gbValue = (byteValue / GB_DIVIDER);
BigDecimal roundedValue = new BigDecimal(gbValue).setScale(SCALE, RoundingMode.HALF_EVEN);
gbValue = roundedValue.doubleValue();
return gbValue;
}
@Override
public double formatSizeInMb(double byteValue) {
double mbValue = (byteValue / MB_DIVIDER);
BigDecimal roundedValue = new BigDecimal(mbValue).setScale(SCALE, RoundingMode.HALF_EVEN);
mbValue = roundedValue.doubleValue();
return mbValue;
}
@Override
public Response evaluateCompatibility() {
if (!(info.getSdkVersion() >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) &&
info.isRooted()) {
return Response.INCOMPATIBLE;
} else if (info.getSdkVersion() < android.os.Build.VERSION_CODES.FROYO) {
return Response.INCOMPATIBLE;
} else if (info.isRooted()) {
return Response.INCOMPATIBLE;
}
return Response.COMPATIBLE;
}
@Override
public String getIpAddress() {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return intToIp(wifiInfo.getIpAddress());
}
@Override
public String intToIp(int ip) {
return (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." +
((ip >> 24) & 0xFF);
}
@Override
public float getBatteryLevel() {
Intent batteryIntent = context.registerReceiver(null,
new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, DEFAULT_LEVEL);
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, DEFAULT_LEVEL);
return ((float) level / (float) scale) * PRECENTAGE_MULTIPLIER;
}
}

View File

@ -1,143 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.api;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
public class GPSTracker extends Service implements LocationListener {
private Location location;
private double latitude;
private double longitude;
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10;
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1;
protected LocationManager locationManager;
public GPSTracker(Context context) {
locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
getLocation();
}
/**
* Function to get device location using GPS.
* @return - Device location coordinates.
*/
private Location getLocation() {
try {
boolean isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(
LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
if (isGpsEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES,
this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(
LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
} catch (RuntimeException e) {
Log.e("Location", "No network/GPS Switched off." + e);
}
return location;
}
/**
* Stop using GPS listener.
* Calling this function will stop using GPS the agent.
*/
public void stopUsingGps() {
if (locationManager != null) {
locationManager.removeUpdates(GPSTracker.this);
}
}
/**
* Function to get latitude.
* @return - Device current latitude.
*/
public double getLatitude() {
if (location != null) {
latitude = location.getLatitude();
}
return latitude;
}
/**
* Function to get longitude.
* @return - Device current longitude.
*/
public double getLongitude() {
if (location != null) {
longitude = location.getLongitude();
}
return longitude;
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}

View File

@ -1,85 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.api;
import java.io.File;
public class Root {
private static final String[] SU_CHECK_COMMAND = new String[] { "/system/xbin/which", "su" };
private static final String SU_TAG = "test-keys";
private static final String SU_APK = "/system/app/Superuser.apk";
/**
* Returns true if the device is rooted (if any of the root methods returns
* true).
* @return - Device rooted status.
*/
public boolean isDeviceRooted() {
if (checkRootBySuAccess()) {
return true;
}
if (checkRootBySuperUserApk()) {
return true;
}
if (checkRootByBuildTags()) {
return true;
}
return false;
}
/**
* Returns true if the OS build tags contains "test-keys".
* @return - Device root status by build tags.
*/
public boolean checkRootByBuildTags() {
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains(SU_TAG)) {
return true;
}
return false;
}
/**
* Returns true if the device contains SuperUser.apk which is stored into
* the device in the rooting process.
* @return - Device root status by SU APK.
*/
public boolean checkRootBySuperUserApk() {
File suApk = new File(SU_APK);
if (suApk != null && suApk.exists()) {
return true;
}
return false;
}
/**
* Executes a shell command (superuser access with su binary) and returns
* true if the command succeeds.
* @return - Device root status by shell access.
*/
public boolean checkRootBySuAccess() {
if (new ShellExecutor().executeCommand(SU_CHECK_COMMAND) != null) {
return true;
} else {
return false;
}
}
}

View File

@ -1,74 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.api;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.wso2.mdm.agent.utils.Constants;
import org.wso2.mdm.agent.utils.StreamHandler;
import android.util.Log;
public class ShellExecutor {
private static final String LOG_TAG = ShellExecutor.class.getName();
/**
* Executes shell commands on the device.
* @param shellCommand - Shell command that needs to be executed.
* @return - Shell command response.
*/
public String executeCommand(String[] shellCommand) {
Process shellProcess = null;
String response = null;
BufferedReader shellInput = null;
try {
if (shellCommand != null) {
shellProcess = Runtime.getRuntime().exec(shellCommand);
}
} catch (IOException e) {
Log.e(LOG_TAG, "Shell command processing failed." + e);
}
if(shellProcess!=null){
shellInput =
new BufferedReader(
new InputStreamReader(
shellProcess.getInputStream())
);
}
try {
while (shellInput!=null && (response = shellInput.readLine()) != null) {
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(LOG_TAG, "Shell Executor Result." + response);
}
}
} catch (IOException e) {
Log.e(LOG_TAG, "Shell input processing failed." + e);
}finally{
StreamHandler.closeBufferedReader(shellInput, LOG_TAG);
}
return response;
}
}

View File

@ -1,134 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.api;
import java.util.List;
import org.wso2.mdm.agent.utils.Constants;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.util.Log;
public class WiFiConfig {
private static ConnectivityManager connectivityManager;
private WifiManager wifiManager;
private static final int WIFI_CONFIG_PRIORITY = 40;
private static final int WIFI_CONFIG_DEFAULT_INDEX = 0;
private static final String TAG = WiFiConfig.class.getName();
public WiFiConfig(Context context) {
wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (!isConnected(context, ConnectivityManager.TYPE_WIFI)) {
wifiManager.setWifiEnabled(true);
}
}
/**
* Checks whether the WIFI is switched on.
* @param context - Application context.
* @param networkType - Network type (WIFI/Data).
*/
private static boolean isConnected(Context context, int networkType) {
NetworkInfo networkInfo = null;
if (connectivityManager != null) {
networkInfo = connectivityManager.getNetworkInfo(networkType);
}
return networkInfo == null ? false : networkInfo.isConnected();
}
/**
* Saves a WEP WIFI Configuration Profile.
* @param ssid - WIFI network SSID.
* @param password - WIFI network password.
*/
public boolean saveWEPConfig(String ssid, String password) {
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = "\"" + ssid + "\"";
wifiConfig.hiddenSSID = true;
wifiConfig.status = WifiConfiguration.Status.DISABLED;
wifiConfig.priority = WIFI_CONFIG_PRIORITY;
wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
wifiConfig.wepKeys[WIFI_CONFIG_DEFAULT_INDEX] = "\"" + password + "\"";
wifiConfig.wepTxKeyIndex = WIFI_CONFIG_DEFAULT_INDEX;
wifiManager.setWifiEnabled(true);
int result = wifiManager.addNetwork(wifiConfig);
boolean isSaveSuccessful = wifiManager.saveConfiguration();
boolean isNetworkEnabled = wifiManager.enableNetwork(result, true);
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(TAG, "add Network returned." + result);
Log.d(TAG, "saveConfiguration returned." + isSaveSuccessful);
Log.d(TAG, "enableNetwork returned." + isNetworkEnabled);
}
return isSaveSuccessful;
}
/**
* Remove WIFI Configuration By SSID.
* @param ssid - SSID of the WIFI profile which needs to be removed.
*/
public boolean removeWifiConfigurationBySsid(String ssid) {
List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks();
boolean isRemoved = false;
for (WifiConfiguration configuration : configuredNetworks) {
if (configuration.SSID.equals(ssid)) {
wifiManager.removeNetwork(configuration.networkId);
wifiManager.saveConfiguration();
isRemoved = true;
break;
}
}
return isRemoved;
}
/**
* Find WIFI Configuration By SSID.
* @param ssid - SSID of the WIFI profile which needs to be found.
*/
public boolean findWifiConfigurationBySsid(String ssid) {
List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks();
boolean isAvailable = false;
for (WifiConfiguration configuration : configuredNetworks) {
if (configuration.SSID.equals(ssid)) {
isAvailable = true;
break;
}
}
return isAvailable;
}
}

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.beans;
public class Battery {
private int scale;
private int level;
private int voltage;
private int temp;
public int getScale() {
return scale;
}
public void setScale(int scale) {
this.scale = scale;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getVoltage() {
return voltage;
}
public void setVoltage(int voltage) {
this.voltage = voltage;
}
public int getTemp() {
return temp;
}
public void setTemp(int temp) {
this.temp = temp;
}
}

View File

@ -1,66 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.beans;
public class DeviceAppInfo {
private String appName;
private String packageName;
private String versionName;
private int versionCode;
private String icon;
public String getAppname() {
return appName;
}
public void setAppname(String appname) {
this.appName = appname;
}
public String getPackagename() {
return packageName;
}
public void setPackagename(String pname) {
this.packageName = pname;
}
public String getVersionName() {
return versionName;
}
public void setVersionName(String versionName) {
this.versionName = versionName;
}
public int getVersionCode() {
return versionCode;
}
public void setVersionCode(int versionCode) {
this.versionCode = versionCode;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
}

View File

@ -1,53 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.beans;
import org.wso2.mdm.agent.utils.Constants;
public class ServerConfig {
private String serverIP;
private String serverURL;
private String APIServerURL;
private static final String COLON = ":";
public String getServerIP() {
return serverIP;
}
public void setServerIP(String serverIP) {
this.serverIP = serverIP;
}
public String getServerURL() {
serverURL = Constants.SERVER_PROTOCOL + serverIP + COLON + Constants.SERVER_PORT;
return serverURL;
}
public void setServerURL(String serverURL) {
this.serverURL = serverURL;
}
public String getAPIServerURL() {
APIServerURL = Constants.SERVER_PROTOCOL + serverIP + COLON + Constants.API_SERVER_PORT;
return APIServerURL;
}
public void setAPIServerURL(String aPIServerURL) {
APIServerURL = aPIServerURL;
}
}

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.factory;
import org.wso2.mdm.agent.api.DeviceStateICS;
import org.wso2.mdm.agent.api.DeviceStateJB;
import org.wso2.mdm.agent.interfaces.DeviceState;
import android.content.Context;
public class DeviceStateFactory {
/**
* Get device state for given SDK version. Creation happens according to the
* device OS version.
* @param context - Application context.
* @param sdkVersion - Device SDK version.
* @return DeviceState API object.
*/
public static DeviceState getDeviceState(Context context, int sdkVersion){
if(sdkVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2){
return new DeviceStateJB(context);
}else{
return new DeviceStateICS(context);
}
}
}

View File

@ -1,93 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.interfaces;
import org.wso2.mdm.agent.utils.Response;
public interface DeviceState {
/**
* Returns whether the external memory is available or not.
* @return - External memory status.
*/
public boolean externalMemoryAvailable();
/**
* Returns the available internal memory size.
* @return - Available internal memory size.
*/
public double getAvailableInternalMemorySize();
/**
* Returns the total internal memory size.
* @return - Total internal memory size.
*/
public double getTotalInternalMemorySize();
/**
* Returns the available external memory size.
* @return - Available external memory size.
*/
public double getAvailableExternalMemorySize();
/**
* Returns the total external memory size.
* @return - Total external memory size.
*/
public double getTotalExternalMemorySize();
/**
* Returns the string formatted value for the size.
* @param byteValue - Memory in bytes.
* @return - Memory formatted into GB.
*/
public double formatSizeInGb(double byteValue);
/**
* Returns the string formatted value for the size.
* @param byteValue
* - Memory in bytes.
* @return - Memory formatted into MB.
*/
public double formatSizeInMb(double byteValue);
/**
* Returns true if the device is compatible to run the agent.
* @return - Device compatibility status.
*/
public Response evaluateCompatibility();
/**
* Returns the device IP address.
* @return - Device IP address.
*/
public String getIpAddress();
/**
* Format the integer IP address and return it as a String.
* @param ip - IP address should be passed in as an Integer.
* @return - Formatted IP address.
*/
public String intToIp(int ip);
/**
* Returns the device battery information.
* @return - Battery level.
*/
public float getBatteryLevel();
}

View File

@ -1,79 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.parsers;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class PayloadParser {
private static final String LABEL_CODE = "code";
private static final String LABEL_REG_ID = "regId";
private static final String LABEL_MESSAGE_ID = "messageId";
private static final String LABEL_DATA = "data";
private static final String TAG = PayloadParser.class.getName();
/**
* Parses the input operation payload.
* @param inputPayload - Operation payload to be parsed.
* @param registrationId - Device registration ID.
* @return - Parsed payload.
*/
public String generateReply(JSONArray inputPayload, String registrationId) {
JSONObject outerJson = new JSONObject();
JSONArray outerArr = new JSONArray();
try {
outerJson.put(LABEL_REG_ID, registrationId);
outerJson.put(LABEL_DATA, outerArr);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON Exception - RegId." + e.toString());
}
for (int i = 0; i < inputPayload.length(); i++) {
try {
String code = inputPayload.getJSONObject(i).getString(LABEL_CODE);
String messageId = inputPayload.getJSONObject(i).getString(LABEL_MESSAGE_ID);
JSONArray data = inputPayload.getJSONObject(i).getJSONArray(LABEL_DATA);
JSONObject dataArrContents = new JSONObject();
dataArrContents.put(LABEL_CODE, code);
JSONArray innerDataArr = new JSONArray();
JSONObject innerDataOb = new JSONObject();
innerDataOb.put(LABEL_MESSAGE_ID, messageId);
innerDataOb.put(LABEL_DATA, data);
innerDataArr.put(innerDataOb);
dataArrContents.put(LABEL_DATA, innerDataArr);
outerArr.put(dataArrContents);
} catch (JSONException e) {
Log.d(TAG, "Invalid JSON Exception - Input payload " + e.toString());
}
}
return outerJson.toString();
}
}

View File

@ -1,138 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.services;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.proxy.interfaces.APIResultCallBack;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import org.wso2.mdm.agent.utils.Constants;
import org.wso2.mdm.agent.utils.Preference;
import org.wso2.mdm.agent.utils.CommonUtils;
import android.app.admin.DeviceAdminReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.util.Log;
import android.widget.Toast;
/**
* This is the component that is responsible for actual device administration.
* It becomes the receiver when a policy is applied. It is important that we
* subclass DeviceAdminReceiver class here and to implement its only required
* method onEnabled().
*/
public class AgentDeviceAdminReceiver extends DeviceAdminReceiver implements APIResultCallBack {
private static final String TAG = AgentDeviceAdminReceiver.class.getName();
private String regId;
/**
* Called when this application is approved to be a device administrator.
*/
@Override
public void onEnabled(Context context, Intent intent) {
super.onEnabled(context, intent);
Resources resources = context.getResources();
Preference.putString(context,
context.getResources().getString(R.string.shared_pref_device_active),
resources.getString(R.string.shared_pref_reg_success));
MessageProcessor processor = new MessageProcessor(context);
processor.getMessages();
Toast.makeText(context, R.string.device_admin_enabled,
Toast.LENGTH_LONG).show();
LocalNotification.startPolling(context);
}
/**
* Called when this application is no longer the device administrator.
*/
@Override
public void onDisabled(Context context, Intent intent) {
super.onDisabled(context, intent);
Toast.makeText(context, R.string.device_admin_disabled,
Toast.LENGTH_LONG).show();
regId = Preference
.getString(context, context.getResources().getString(R.string.shared_pref_regId));
if (regId != null && !regId.isEmpty()) {
startUnRegistration(context);
}
}
/**
* Start un-registration process.
* @param context - Application context.
*/
public void startUnRegistration(Context context) {
String regId = Preference.getString(context, context
.getResources().getString(R.string.shared_pref_regId));
JSONObject requestParams = new JSONObject();
try {
requestParams.put(context.getResources().getString(R.string.shared_pref_regId), regId);
} catch (JSONException e) {
Log.e(TAG, "Registration ID not retrieved." + e.toString());
}
CommonUtils.clearAppData(context);
CommonUtils.callSecuredAPI(context,
Constants.UNREGISTER_ENDPOINT,
HTTP_METHODS.POST, requestParams,
AgentDeviceAdminReceiver.this,
Constants.UNREGISTER_REQUEST_CODE);
}
@Override
public void onPasswordChanged(Context context, Intent intent) {
super.onPasswordChanged(context, intent);
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(TAG, "onPasswordChanged.");
}
}
@Override
public void onPasswordFailed(Context context, Intent intent) {
super.onPasswordFailed(context, intent);
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(TAG, "onPasswordFailed.");
}
}
@Override
public void onPasswordSucceeded(Context context, Intent intent) {
super.onPasswordSucceeded(context, intent);
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(TAG, "onPasswordSucceeded.");
}
}
@Override
public void onReceiveAPIResult(Map<String, String> arg0, int arg1) {
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(TAG, "Unregistered." + arg0.toString());
}
}
}

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.services;
import org.wso2.mdm.agent.utils.Constants;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class AlarmReceiver extends BroadcastReceiver {
private static final String DEBUG_TAG = AlarmReceiver.class.getName();
@Override
public void onReceive(Context context, Intent intent) {
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(DEBUG_TAG, "Recurring alarm; requesting alarm service.");
}
MessageProcessor messageProcessor = new MessageProcessor(context);
messageProcessor.getMessages();
}
}

View File

@ -1,112 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.services;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.mdm.agent.api.DeviceInfo;
import android.content.Context;
import android.util.Log;
public class BuildDeviceInfoPayload {
private JSONObject result;
private DeviceInfo deviceInfo;
private static final String TAG = BuildDeviceInfoPayload.class.getName();
private static final String DEVICE_IDENTIFIER = "deviceIdentifier";
private static final String DEVICE_DESCRIPTION = "description";
private static final String DEVICE_OWNERSHIP = "ownership";
private static final String DEVICE_PROPERTY_NAME = "name";
private static final String DEVICE_PROPERTY_VALUE = "value";
private static final String DEVICE_PROPERTY_USERNAME = "username";
private static final String DEVICE_PROPERTY_DESCRIPTION = "device";
private static final String DEVICE_PROPERTY_IMEI = "imei";
private static final String DEVICE_PROPERTY_IMSI = "imsi";
private static final String DEVICE_PROPERTY_MODEL = "model";
private static final String DEVICE_PROPERTY_VENDOR = "vendor";
private static final String DEVICE_PROPERTY_OS = "osVersion";
private static final String DEVICE_PROPERTY_TAG = "properties";
public BuildDeviceInfoPayload(Context context){
deviceInfo = new DeviceInfo(context.getApplicationContext());
}
/**
* Builds device information payload.
* @param type - Device ownership type.
* @param username - Current user name.
*/
public void build(String type, String username){
result = new JSONObject();
try{
result.put(DEVICE_IDENTIFIER, deviceInfo.getMACAddress());
result.put(DEVICE_DESCRIPTION, deviceInfo.getDeviceName());
result.put(DEVICE_OWNERSHIP, type);
JSONArray properties = new JSONArray();
JSONObject property = new JSONObject();
property.put(DEVICE_PROPERTY_NAME, DEVICE_PROPERTY_USERNAME);
property.put(DEVICE_PROPERTY_VALUE, username);
properties.put(property);
property = new JSONObject();
property.put(DEVICE_PROPERTY_NAME, DEVICE_PROPERTY_DESCRIPTION);
property.put(DEVICE_PROPERTY_VALUE, deviceInfo.getDeviceName());
properties.put(property);
property = new JSONObject();
property.put(DEVICE_PROPERTY_NAME, DEVICE_PROPERTY_IMEI);
property.put(DEVICE_PROPERTY_VALUE, deviceInfo.getDeviceId());
properties.put(property);
property = new JSONObject();
property.put(DEVICE_PROPERTY_NAME, DEVICE_PROPERTY_IMSI);
property.put(DEVICE_PROPERTY_VALUE, deviceInfo.getIMSINumber());
properties.put(property);
property = new JSONObject();
property.put(DEVICE_PROPERTY_NAME, DEVICE_PROPERTY_MODEL);
property.put(DEVICE_PROPERTY_VALUE, deviceInfo.getDeviceModel());
properties.put(property);
property = new JSONObject();
property.put(DEVICE_PROPERTY_NAME, DEVICE_PROPERTY_VENDOR);
property.put(DEVICE_PROPERTY_VALUE, deviceInfo.getOsVersion());
properties.put(property);
property = new JSONObject();
property.put(DEVICE_PROPERTY_NAME, DEVICE_PROPERTY_OS);
property.put(DEVICE_PROPERTY_VALUE, deviceInfo.getOsVersion());
properties.put(property);
result.put(DEVICE_PROPERTY_TAG, properties);
}catch(JSONException e){
Log.e(TAG, "Invalid object saved in JSON.");
}
}
/**
* Returns the final payload.
* @return - Device info payload.
*/
public JSONObject getDeviceInfoPayload(){
return this.result;
}
}

View File

@ -1,132 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.services;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.mdm.agent.R;
import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
public class BuildResultPayload {
private JSONArray operationListResult;
private JSONObject result;
private Resources resources;
private String TAG = BuildResultPayload.class.getName();
public BuildResultPayload(Context context){
this.resources = context.getResources();
this.operationListResult = new JSONArray();
this.result = new JSONObject();
}
/**
* Add operation results to the array to be returned.
* @param code - Operation code.
*/
public void build(String code) {
try {
result.put(resources.getString(R.string.intent_extra_status),
resources.getString(R.string.shared_pref_default_status));
result.put(resources.getString(R.string.intent_extra_code), code);
operationListResult.put(result);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e.toString());
}
}
/**
* Add operation results to the array to be returned.
* @param code - Operation code.
* @param data - Data JSON object.
*/
public void build(String code, JSONObject data) {
try {
result.put(resources.getString(R.string.intent_extra_status),
resources.getString(R.string.shared_pref_default_status));
result.put(resources.getString(R.string.intent_extra_code), code);
if (data != null) {
result.put(resources.getString(R.string.intent_extra_data), data);
}
operationListResult.put(result);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e.toString());
}
}
/**
* Add operation results to the array to be returned.
* @param code - Operation code.
* @param dataList - Data JSON Array.
*/
public void build(String code, JSONArray dataList) {
try {
result.put(resources.getString(R.string.intent_extra_status),
resources.getString(R.string.shared_pref_default_status));
result.put(resources.getString(R.string.intent_extra_code), code);
if (dataList != null) {
result.put(resources.getString(R.string.intent_extra_data), dataList);
}
operationListResult.put(result);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e.toString());
}
}
/**
* Add operation results to the array to be returned.
* @param code - Operation code.
* @param customStatus - Operation status.
*/
public void build(String code, String customStatus) {
try {
if (customStatus != null) {
result.put(resources.getString(R.string.intent_extra_status), customStatus);
} else {
result.put(resources.getString(R.string.intent_extra_status),
resources.getString(R.string.shared_pref_default_status));
}
result.put(resources.getString(R.string.intent_extra_code), code);
operationListResult.put(result);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e.toString());
}
}
/**
* Return final results payload.
* @return - Final payload.
*/
public JSONArray getResultPayload(){
return this.operationListResult;
}
}

View File

@ -1,72 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.services;
import java.util.Locale;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.utils.Preference;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.SystemClock;
public class DeviceStartupIntentReceiver extends BroadcastReceiver {
private static final String NOTIFIER_MODE = "LOCAL";
private static final int DEFAULT_TIME_MILLISECONDS = 1000;
private static final int DEFAULT_REQUEST_CODE = 0;
private Resources resources;
@Override
public void onReceive(final Context context, Intent intent) {
setRecurringAlarm(context.getApplicationContext());
}
/**
* Initiates device notifier on device startup.
* @param context - Application context.
*/
private void setRecurringAlarm(Context context) {
this.resources = context.getApplicationContext().getResources();
String mode =
Preference
.getString(context, resources.getString(R.string.shared_pref_message_mode));
Float interval =
(Float) Preference
.getFloat(context, resources.getString(R.string.shared_pref_interval));
if (mode.trim().toUpperCase(Locale.ENGLISH).equals(NOTIFIER_MODE)) {
long startTime = SystemClock.elapsedRealtime() + DEFAULT_TIME_MILLISECONDS;
Intent alarmIntent = new Intent(context, AlarmReceiver.class);
PendingIntent recurringAlarmIntent =
PendingIntent.getBroadcast(context,
DEFAULT_REQUEST_CODE,
alarmIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager =
(AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, startTime,
interval.intValue(), recurringAlarmIntent);
}
}
}

View File

@ -1,54 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.services;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
/**
* Local notification is a communication mechanism that essentially,
* polls to server based on a predefined to retrieve pending data.
*/
public class LocalNotification {
public static boolean localNoticicationInvoked = false;
public static int DEFAULT_INTERVAL = 10000;
public static int DEFAULT_BUFFER = 1000;
public static int REQUEST_CODE = 0;
public static void startPolling(Context context) {
int interval = DEFAULT_INTERVAL;
long currentTime = SystemClock.elapsedRealtime();
currentTime += DEFAULT_BUFFER;
if (localNoticicationInvoked == false) {
localNoticicationInvoked = true;
Intent alarm = new Intent(context, AlarmReceiver.class);
PendingIntent recurringAlarm =
PendingIntent.getBroadcast(context,
REQUEST_CODE,
alarm,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarms.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, currentTime, interval,
recurringAlarm);
}
}
}

View File

@ -1,134 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.services;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.api.DeviceInfo;
import org.wso2.mdm.agent.beans.ServerConfig;
import org.wso2.mdm.agent.proxy.interfaces.APIResultCallBack;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import org.wso2.mdm.agent.utils.Constants;
import org.wso2.mdm.agent.utils.Preference;
import org.wso2.mdm.agent.utils.CommonUtils;
import android.content.Context;
import android.util.Log;
/**
* Used to coordinate the retrieval and processing of messages from the server.
*/
public class MessageProcessor implements APIResultCallBack {
private String TAG = MessageProcessor.class.getSimpleName();
private Context context;
private String deviceId;
private static final String DEVICE_ID_PREFERENCE_KEY = "deviceId";
private static final String ENCODE_METHOD_UTF_8 = "utf-8";
/**
* Local notification message handler.
* @param context Context of the application.
*/
public MessageProcessor(Context context) {
this.context = context;
deviceId = Preference.getString(context, DEVICE_ID_PREFERENCE_KEY);
if (deviceId == null) {
DeviceInfo deviceInfo = new DeviceInfo(context.getApplicationContext());
deviceId = deviceInfo.getMACAddress();
Preference.putString(context, DEVICE_ID_PREFERENCE_KEY, deviceId);
}
}
/**
* @param response Response received from the server that needs to be processed
* and applied to the device.
*/
public void performOperation(String response) {
try {
JSONArray operations = new JSONArray(response);
for (int i = 0; i < operations.length(); i++) {
String featureCode = operations.getJSONObject(i).getString(Constants.CODE);
String properties = operations.getJSONObject(i).getString(Constants.PROPERTIES);
Operation operation = new Operation(context.getApplicationContext());
operation.doTask(featureCode, properties);
}
} catch (JSONException e) {
Log.e(TAG, "JSON Exception in response String." + e.toString());
}
}
/**
* Call the message retrieval end point of the server to get messages
* pending.
*/
public void getMessages() {
String ipSaved =
Preference.getString(context.getApplicationContext(),
context.getResources().getString(R.string.shared_pref_ip));
ServerConfig utils = new ServerConfig();
utils.setServerIP(ipSaved);
String deviceIdentifier = null;
try {
deviceIdentifier = URLEncoder.encode(deviceId, ENCODE_METHOD_UTF_8);
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unsupport encoding." + e.toString());
}
CommonUtils.callSecuredAPI(context, utils.getAPIServerURL() +
Constants.NOTIFICATION_ENDPOINT + File.separator +
deviceIdentifier,
HTTP_METHODS.GET, new JSONObject(), MessageProcessor.this,
Constants.NOTIFICATION_REQUEST_CODE
);
}
@Override
public void onReceiveAPIResult(Map<String, String> result, int requestCode) {
String responseStatus;
String response;
if (requestCode == Constants.NOTIFICATION_REQUEST_CODE) {
if (result != null) {
responseStatus = result.get(Constants.STATUS_KEY);
if (responseStatus != null &&
responseStatus.equals(Constants.REQUEST_SUCCESSFUL)) {
response = result.get(Constants.RESPONSE);
if (response != null && !response.isEmpty()) {
if (Constants.DEBUG_MODE_ENABLED) {
Log.d(TAG, "onReceiveAPIResult." + response);
}
performOperation(response);
}
}
}
}
}
}

View File

@ -1,896 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.services;
import java.util.ArrayList;
import java.util.Map;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.AlertActivity;
import org.wso2.mdm.agent.ServerDetails;
import org.wso2.mdm.agent.api.ApplicationManager;
import org.wso2.mdm.agent.api.DeviceInfo;
import org.wso2.mdm.agent.api.GPSTracker;
import org.wso2.mdm.agent.api.WiFiConfig;
import org.wso2.mdm.agent.beans.DeviceAppInfo;
import org.wso2.mdm.agent.factory.DeviceStateFactory;
import org.wso2.mdm.agent.interfaces.DeviceState;
import org.wso2.mdm.agent.utils.Constants;
import org.wso2.mdm.agent.utils.Preference;
import org.wso2.mdm.agent.utils.CommonUtils;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.media.AudioManager;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
public class Operation {
private Context context;
private DevicePolicyManager devicePolicyManager;
private ApplicationManager appList;
private Resources resources;
private BuildResultPayload resultBuilder;
private static final String TAG = "Operation Handler";
private static final String MEMORY_INFO_TAG_TOTAL = "total";
private static final String MEMORY_INFO_TAG_AVAILABLE = "available";
private static final String MEMORY_INFO_TAG_INTERNAL = "internal_memory";
private static final String MEMORY_INFO_TAG_EXTERNAL = "external_memory";
private static final String BATTERY_INFO_TAG_LEVEL = "level";
private static final String BATTERY_INFO_TAG = "battery";
private static final String LOCATION_INFO_TAG_LONGITUDE = "longitude";
private static final String LOCATION_INFO_TAG_LATITUDE = "latitude";
private static final String LOCATION_INFO_TAG = "location_obj";
private static final String NETWORK_OPERATOR_TAG = "operator";
private static final String APP_INFO_TAG_NAME = "name";
private static final String APP_INFO_TAG_PACKAGE = "package";
private static final String APP_INFO_TAG_ICON = "icon";
private static final int PRE_WIPE_WAIT_TIME = 4000;
private static final int ACTIVATION_REQUEST = 47;
private static final int DEFAULT_PASSWORD_LENGTH = 0;
private static final int DEFAULT_VOLUME = 0;
private static final int DEFAULT_FLAG = 0;
private static final int DEFAULT_PASSWORD_MIN_LENGTH = 3;
private static final long DAY_MILLISECONDS_MULTIPLIER = 24 * 60 * 60 * 1000;
private Map<String, String> bundleParams;
public Operation(Context context) {
this.context = context;
this.resources = context.getResources();
this.devicePolicyManager =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
this.appList = new ApplicationManager(context.getApplicationContext());
this.resultBuilder = new BuildResultPayload(context.getApplicationContext());
}
/**
* Executes device management operations on the device.
* @param operationCode - Device management operation code.
* @param operationData - Operation data if required(ex:WIFI configuration).
* @param requestMode - Request mode (GCM/Local).
* @return Operation/Policy status list.
*/
public JSONArray doTask(String operationCode, String operationData) {
switch (operationCode) {
case Constants.OPERATION_DEVICE_INFO:
getDeviceInfo(operationCode);
break;
case Constants.OPERATION_DEVICE_LOCATION:
getLocationInfo(operationCode);
break;
case Constants.OPERATION_GET_APPLICATION_LIST:
getApplicationList(operationCode);
break;
case Constants.OPERATION_LOCK_DEVICE:
lockDevice(operationCode);
break;
case Constants.OPERATION_WIPE_DATA:
wipeDevice(operationCode, operationData);
break;
case Constants.OPERATION_CLEAR_PASSWORD:
clearPassword(operationCode);
break;
case Constants.OPERATION_NOTIFICATION:
displayNotification(operationCode);
break;
case Constants.OPERATION_WIFI:
configureWifi(operationCode, operationData);
break;
case Constants.OPERATION_DISABLE_CAMERA:
disableCamera(operationCode, operationData);
break;
case Constants.OPERATION_INSTALL_APPLICATION:
installAppBundle(operationCode, operationData);
break;
case Constants.OPERATION_INSTALL_APPLICATION_BUNDLE:
installAppBundle(operationCode, operationData);
break;
case Constants.OPERATION_UNINSTALL_APPLICATION:
uninstallApplication(operationCode, operationData);
break;
case Constants.OPERATION_ENCRYPT_STORAGE:
encryptStorage(operationCode, operationData);
break;
case Constants.OPERATION_RING:
ringDevice(operationCode);
break;
case Constants.OPERATION_MUTE:
muteDevice(operationCode);
break;
case Constants.OPERATION_WEBCLIP:
createWebClip(operationCode, operationData);
break;
case Constants.OPERATION_PASSWORD_POLICY:
setPasswordPolicy(operationCode, operationData);
break;
case Constants.OPERATION_INSTALL_GOOGLE_APP:
installGooglePlayApp(operationCode, operationData);
break;
case Constants.OPERATION_CHANGE_LOCK_CODE:
changeLockCode(operationCode, operationData);
break;
case Constants.OPERATION_POLICY_BUNDLE:
setPolicyBundle(operationCode);
break;
case Constants.OPERATION_ENTERPRISE_WIPE_DATA:
enterpriseWipe(operationCode);
break;
case Constants.OPERATION_BLACKLIST_APPS:
blacklistApps(operationCode, operationData);
break;
default:
Log.e(TAG, "Invalid operation code receieved");
break;
}
return resultBuilder.getResultPayload();
}
/**
* Retrieve device information.
* @param code - Operation code.
*/
public void getDeviceInfo(String code) {
DeviceInfo deviceInfo = new DeviceInfo(context.getApplicationContext());
DeviceState phoneState = DeviceStateFactory.getDeviceState(context.getApplicationContext(),
deviceInfo.getSdkVersion());
GPSTracker gps = new GPSTracker(context.getApplicationContext());
JSONObject result = new JSONObject();
JSONObject batteryInfo = new JSONObject();
JSONObject internalMemoryInfo = new JSONObject();
JSONObject externalMemoryInfo = new JSONObject();
JSONObject locationInfo = new JSONObject();
double latitude;
double longitude;
try {
latitude = gps.getLatitude();
longitude = gps.getLongitude();
int batteryLevel = (int) Math.floor(phoneState.getBatteryLevel());
batteryInfo.put(BATTERY_INFO_TAG_LEVEL, batteryLevel);
internalMemoryInfo.put(MEMORY_INFO_TAG_TOTAL, phoneState.getTotalInternalMemorySize());
internalMemoryInfo.put(MEMORY_INFO_TAG_AVAILABLE,
phoneState.getAvailableInternalMemorySize());
externalMemoryInfo.put(MEMORY_INFO_TAG_TOTAL, phoneState.getTotalExternalMemorySize());
externalMemoryInfo.put(MEMORY_INFO_TAG_AVAILABLE,
phoneState.getAvailableExternalMemorySize());
locationInfo.put(LOCATION_INFO_TAG_LATITUDE, latitude);
locationInfo.put(LOCATION_INFO_TAG_LONGITUDE, longitude);
result.put(BATTERY_INFO_TAG, batteryInfo);
result.put(MEMORY_INFO_TAG_INTERNAL, internalMemoryInfo);
result.put(MEMORY_INFO_TAG_EXTERNAL, externalMemoryInfo);
if (latitude != 0 && longitude != 0) {
result.put(LOCATION_INFO_TAG, locationInfo);
}
result.put(NETWORK_OPERATOR_TAG, deviceInfo.getNetworkOperatorName());
resultBuilder.build(code, result);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Retrieve device information.
* @param code - Operation code.
*/
public void getLocationInfo(String code) {
double latitude;
double longitude;
JSONObject result = new JSONObject();
GPSTracker gps = new GPSTracker(context);
try {
latitude = gps.getLatitude();
longitude = gps.getLongitude();
result.put(LOCATION_INFO_TAG_LATITUDE, latitude);
result.put(LOCATION_INFO_TAG_LONGITUDE, longitude);
resultBuilder.build(code, result);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Retrieve device application information.
* @param code - Operation code.
*/
public void getApplicationList(String code) {
ArrayList<DeviceAppInfo> apps = appList.getInstalledApps();
JSONArray result = new JSONArray();
int size = apps.size();
for (int i = 0; i < size; i++) {
JSONObject app = new JSONObject();
try {
app.put(APP_INFO_TAG_NAME, Uri.encode(apps.get(i).getAppname()));
app.put(APP_INFO_TAG_PACKAGE, apps.get(i).getPackagename());
app.put(APP_INFO_TAG_ICON, apps.get(i).getIcon());
result.put(app);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
resultBuilder.build(code, result);
}
/**
* Lock the device.
* @param code - Operation code.
*/
public void lockDevice(String code) {
resultBuilder.build(code);
devicePolicyManager.lockNow();
}
/**
* Ring the device.
* @param code - Operation code.
*/
public void ringDevice(String code) {
resultBuilder.build(code);
devicePolicyManager.lockNow();
}
/**
* Wipe the device.
* @param code - Operation code.
* @param data - Data required by the operation(PIN).
*/
public void wipeDevice(String code, String data) {
String inputPin;
String savedPin =
Preference.getString(context,
resources.getString(R.string.shared_pref_pin));
try {
JSONObject wipeKey = new JSONObject(data);
inputPin = (String) wipeKey.get(resources.getString(R.string.shared_pref_pin));
String status;
if (inputPin.trim().equals(savedPin.trim())) {
status = resources.getString(R.string.shared_pref_default_status);
} else {
status = resources.getString(R.string.shared_pref_false_status);
}
resultBuilder.build(code, status);
if (inputPin.trim().equals(savedPin.trim())) {
Toast.makeText(context, resources.getString(R.string.toast_message_wipe),
Toast.LENGTH_LONG).show();
try {
Thread.sleep(PRE_WIPE_WAIT_TIME);
} catch (InterruptedException e) {
Log.e(TAG, "Wipe pause interrupted :" + e.toString());
}
devicePolicyManager.wipeData(ACTIVATION_REQUEST);
} else {
Toast.makeText(context, resources.getString(R.string.toast_message_wipe_failed),
Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Clear device password.
* @param code - Operation code.
* @param requestMode - Request mode(Normal mode or policy bundle mode).
*/
public void clearPassword(String code) {
ComponentName demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
resultBuilder.build(code);
devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, DEFAULT_PASSWORD_LENGTH);
devicePolicyManager.resetPassword(resources.getString(R.string.shared_pref_default_string),
DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
devicePolicyManager.lockNow();
devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
}
/**
* Display notification.
* @param code - Operation code.
*/
public void displayNotification(String code) {
String notification = null;
try {
JSONObject inputData = new JSONObject(code);
if (inputData.get(resources.getString(R.string.intent_extra_notification)).toString() !=
null &&
!inputData.get(resources.getString(R.string.intent_extra_notification)).toString()
.isEmpty()) {
notification =
inputData.get(resources.getString(R.string.intent_extra_notification))
.toString();
}
resultBuilder.build(code);
if (notification != null) {
Intent intent = new Intent(context, AlertActivity.class);
intent.putExtra(resources.getString(R.string.intent_extra_message), notification);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Configure device WIFI profile.
* @param code - Operation code.
* @param data - Data required(SSID, Password).
* @param requestMode - Request mode(Normal mode or policy bundle mode).
*/
public void configureWifi(String code, String data) {
boolean wifistatus = false;
String ssid = null;
String password = null;
try {
JSONObject wifiData = new JSONObject(data);
if (!wifiData.isNull(resources.getString(R.string.intent_extra_ssid))) {
ssid = (String) wifiData.get(resources.getString(R.string.intent_extra_ssid));
}
if (!wifiData.isNull(resources.getString(R.string.intent_extra_password))) {
password =
(String) wifiData.get(resources.getString(R.string.intent_extra_password));
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format " + e.toString());
}
WiFiConfig config = new WiFiConfig(context.getApplicationContext());
wifistatus = config.saveWEPConfig(ssid, password);
String status = null;
if (wifistatus) {
status = resources.getString(R.string.shared_pref_default_status);
} else {
status = resources.getString(R.string.shared_pref_false_status);
}
resultBuilder.build(code, status);
}
/**
* Disable/Enable device camera.
* @param code - Operation code.
* @param data - Data required(Camera enable/disable switch).
* @param requestMode - Request mode(Normal mode or policy bundle mode).
*/
public void disableCamera(String code, String data) {
boolean camFunc = false;
try {
JSONObject inputData = new JSONObject(data);
if (!inputData.isNull(resources.getString(R.string.intent_extra_function)) &&
inputData.get(resources.getString(R.string.intent_extra_function)).toString()
.equalsIgnoreCase(resources.getString(R.string.intent_extra_enable))) {
camFunc = false;
} else if (!inputData.isNull(resources.getString(R.string.intent_extra_function)) &&
inputData.get(resources.getString(R.string.intent_extra_function)).toString()
.equalsIgnoreCase(
resources.getString(R.string.intent_extra_disable))) {
camFunc = true;
} else if (!inputData.isNull(resources.getString(R.string.intent_extra_function))) {
camFunc =
Boolean.parseBoolean(
inputData.get(resources.getString(R.string.intent_extra_function))
.toString());
}
ComponentName cameraAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
resultBuilder.build(code);
devicePolicyManager.setCameraDisabled(cameraAdmin, camFunc);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Install application/bundle.
* @param code - Operation code.
* @param data - Data required(App data).
*/
public void installAppBundle(String code, String data) {
try {
resultBuilder.build(code);
if (code.equals(Constants.OPERATION_INSTALL_APPLICATION)) {
JSONObject appData = new JSONObject(data);
installApplication(appData, code);
} else if (code.equals(Constants.OPERATION_INSTALL_APPLICATION_BUNDLE)) {
JSONArray jArray = null;
jArray = new JSONArray(data);
for (int i = 0; i < jArray.length(); i++) {
JSONObject appObj = (JSONObject) jArray.getJSONObject(i);
installApplication(appObj, code);
}
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Uninstall application.
* @param code - Operation code.
* @param data - Data required(App package).
*/
public void uninstallApplication(String code, String data) {
String packageName;
try {
JSONObject appData = new JSONObject(data);
packageName = (String) appData.get(resources.getString(R.string.intent_extra_identity));
resultBuilder.build(code);
appList.uninstallApplication(packageName);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Encrypt/Decrypt device storage.
* @param code - Operation code.
* @param data - Data required(Encryption enable/disable switch).
* @param requestMode - Request mode(Normal mode or policy bundle mode).
*/
public void encryptStorage(String code, String data) {
boolean doEncrypt = true;
try {
JSONObject encryptData = new JSONObject(data);
if (!encryptData.isNull(resources.getString(R.string.intent_extra_function)) &&
encryptData.get(resources.getString(R.string.intent_extra_function)).toString()
.equalsIgnoreCase(resources.getString(R.string.intent_extra_encrypt))) {
doEncrypt = true;
} else if (!encryptData.isNull(resources.getString(R.string.intent_extra_function)) &&
encryptData.get(resources.getString(R.string.intent_extra_function))
.toString()
.equalsIgnoreCase(
resources.getString(R.string.intent_extra_decrypt))) {
doEncrypt = false;
} else if (!encryptData.isNull(resources.getString(R.string.intent_extra_function))) {
doEncrypt =
Boolean.parseBoolean(
encryptData.get(resources.getString(R.string.intent_extra_function))
.toString());
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
ComponentName admin = new ComponentName(context, AgentDeviceAdminReceiver.class);
if (doEncrypt &&
devicePolicyManager.getStorageEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED &&
(devicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE)) {
devicePolicyManager.setStorageEncryption(admin, doEncrypt);
Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else if (!doEncrypt &&
devicePolicyManager.getStorageEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED &&
(devicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE ||
devicePolicyManager.getStorageEncryptionStatus() == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVATING)) {
devicePolicyManager.setStorageEncryption(admin, doEncrypt);
}
String status;
if (devicePolicyManager.getStorageEncryptionStatus() !=
DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
status = resources.getString(R.string.shared_pref_default_status);
} else {
status = resources.getString(R.string.shared_pref_false_status);
}
resultBuilder.build(code, status);
}
/**
* Mute the device.
* @param code - Operation code.
* @param requestMode - Request mode(Normal mode or policy bundle mode).
*/
private void muteDevice(String code) {
resultBuilder.build(code);
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_RING, DEFAULT_VOLUME, DEFAULT_FLAG);
}
/**
* Create web clip (Web app shortcut on device home screen).
* @param code - Operation code.
* @param data - Data required(Web app data).
*/
public void createWebClip(String code, String data) {
String appUrl = null;
String title = null;
try {
JSONObject webClipData = new JSONObject(code);
appUrl = (String) webClipData.get(resources.getString(R.string.intent_extra_identity));
title = (String) webClipData.get(resources.getString(R.string.intent_extra_title));
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format. " + e);
}
resultBuilder.build(data);
if(appUrl!=null && title!=null){
appList.createWebAppBookmark(appUrl, title);
}
}
/**
* Set device password policy.
* @param code - Operation code.
* @param data - Data required (Password policy parameters).
* @param requestMode - Request mode(Normal mode or policy bundle mode).
*/
public void setPasswordPolicy(String code, String data) {
ComponentName demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
int attempts, length, history, specialChars;
String alphanumeric, complex;
boolean isAlphanumeric, isComplex;
long timout;
resultBuilder.build(code);
try {
JSONObject policyData = new JSONObject(data);
if (!policyData
.isNull(resources.getString(R.string.policy_password_max_failed_attempts)) &&
policyData.get(resources.getString(R.string.policy_password_max_failed_attempts)) !=
null) {
attempts =
Integer.parseInt((String) policyData.get(resources.getString(
R.string.policy_password_max_failed_attempts)));
devicePolicyManager.setMaximumFailedPasswordsForWipe(demoDeviceAdmin, attempts);
}
if (!policyData.isNull(resources.getString(R.string.policy_password_min_length)) &&
policyData.get(resources.getString(R.string.policy_password_min_length)) != null) {
length =
Integer.parseInt((String) policyData
.get(resources.getString(R.string.policy_password_min_length)));
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, length);
}
if (!policyData.isNull(resources.getString(R.string.policy_password_pin_history)) &&
policyData.get(resources.getString(R.string.policy_password_pin_history)) != null) {
history =
Integer.parseInt((String) policyData
.get(resources.getString(R.string.policy_password_pin_history)));
devicePolicyManager.setPasswordHistoryLength(demoDeviceAdmin, history);
}
if (!policyData
.isNull(resources.getString(R.string.policy_password_min_complex_chars)) &&
policyData.get(resources.getString(R.string.policy_password_min_complex_chars)) !=
null) {
specialChars =
Integer.parseInt((String) policyData.get(resources.getString(
R.string.policy_password_min_complex_chars)));
devicePolicyManager.setPasswordMinimumSymbols(demoDeviceAdmin, specialChars);
}
if (!policyData
.isNull(resources.getString(R.string.policy_password_require_alphanumeric)) &&
policyData
.get(resources.getString(R.string.policy_password_require_alphanumeric)) !=
null) {
if (policyData.get(resources.getString(
R.string.policy_password_require_alphanumeric)) instanceof String) {
alphanumeric =
(String) policyData.get(resources.getString(
R.string.policy_password_require_alphanumeric));
if (alphanumeric
.equals(resources.getString(R.string.shared_pref_default_status))) {
devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
}
} else if (policyData.get(resources.getString(
R.string.policy_password_require_alphanumeric)) instanceof Boolean) {
isAlphanumeric =
policyData.getBoolean(resources.getString(
R.string.policy_password_require_alphanumeric));
if (isAlphanumeric) {
devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
}
}
}
if (!policyData.isNull(resources.getString(R.string.policy_password_allow_simple)) &&
policyData.get(resources.getString(R.string.policy_password_allow_simple)) !=
null) {
if (policyData.get(resources.getString(
R.string.policy_password_allow_simple)) instanceof String) {
complex =
(String) policyData.get(resources.getString(
R.string.policy_password_allow_simple));
if (!complex.equals(resources.getString(R.string.shared_pref_default_status))) {
devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);
}
} else if (policyData.get(resources.getString(
R.string.policy_password_allow_simple)) instanceof Boolean) {
isComplex =
policyData.getBoolean(
resources.getString(R.string.policy_password_allow_simple));
if (!isComplex) {
devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);
}
}
}
if (!policyData.isNull(resources.getString(R.string.policy_password_pin_age_in_days)) &&
policyData.get(resources.getString(R.string.policy_password_pin_age_in_days)) !=
null) {
int daysOfExp =
Integer.parseInt((String) policyData.get(resources.getString(
R.string.policy_password_pin_age_in_days)));
timout = (long) (daysOfExp * DAY_MILLISECONDS_MULTIPLIER);
devicePolicyManager.setPasswordExpirationTimeout(demoDeviceAdmin, timout);
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Install google play applications.
* @param code - Operation code.
* @param data - Data required(App data).
*/
public void installGooglePlayApp(String code, String data) {
String packageName = null;
try {
JSONObject appData = new JSONObject(data);
packageName = (String) appData.get(resources.getString(R.string.intent_extra_package));
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
resultBuilder.build(code);
triggerGooglePlayApp(packageName);
}
/**
* Open Google Play store application with an application given.
* @param packageName - Application package name.
*/
public void triggerGooglePlayApp(String packageName) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(Constants.GOOGLE_PLAY_APP_URI + packageName));
context.startActivity(intent);
}
/**
* Change device lock code.
* @param code - Operation code.
* @param data - Data required(Lock code).
*/
public void changeLockCode(String code, String data) {
ComponentName demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, DEFAULT_PASSWORD_MIN_LENGTH);
String password = null;
try {
JSONObject lockData = new JSONObject(data);
if (!lockData.isNull(resources.getString(R.string.intent_extra_password))) {
password =
(String) lockData.get(resources.getString(R.string.intent_extra_password));
}
resultBuilder.build(code);
if (password!=null && !password.isEmpty()) {
devicePolicyManager.resetPassword(password,
DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
devicePolicyManager.lockNow();
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Set policy bundle.
* @param code - Operation code.
*/
public void setPolicyBundle(String code) {
try {
resultBuilder.build(code, new JSONObject(bundleParams.toString()));
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
/**
* Enterprise wipe the device.
* @param code - Operation code.
*/
public void enterpriseWipe(String code) {
resultBuilder.build(code);
CommonUtils.clearAppData(context);
Intent intent = new Intent(context, ServerDetails.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
/**
* Blacklisting apps.
* @param code - Operation code.
* @param data - Data required(Application data).
*/
public void blacklistApps(String code, String data) {
ArrayList<DeviceAppInfo> apps = appList.getInstalledApps();
JSONArray appList = new JSONArray();
String identity = null;
try {
JSONObject resultApp = new JSONObject(data);
if (!resultApp.isNull(resources.getString(R.string.intent_extra_data))) {
resultApp =
(JSONObject) resultApp.get(resources.getString(R.string.intent_extra_data));
}
identity = (String) resultApp.get(resources.getString(R.string.intent_extra_identity));
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
for (DeviceAppInfo app : apps) {
JSONObject result = new JSONObject();
try {
result.put(resources.getString(R.string.intent_extra_name), app.getAppname());
result.put(resources.getString(R.string.intent_extra_package),
app.getPackagename());
if (identity.trim().equals(app.getPackagename())) {
result.put(resources.getString(R.string.intent_extra_not_violated), false);
result.put(resources.getString(R.string.intent_extra_package),
app.getPackagename());
} else {
result.put(resources.getString(R.string.intent_extra_not_violated), true);
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
appList.put(result);
}
resultBuilder.build(code, appList);
}
/**
* Install an Application
*/
private void installApplication(JSONObject data, String code) {
String appUrl = null;
String type = null;
String os = null;
try {
JSONObject applicationData = data;
appUrl = (String) applicationData
.get(resources.getString(R.string.intent_extra_identity));
if (!applicationData.isNull(resources.getString(R.string.intent_extra_type))) {
type = (String) applicationData
.get(resources.getString(R.string.intent_extra_type));
}
if (!applicationData.isNull(resources.getString(R.string.intent_extra_platform_id))) {
os = (String) applicationData
.get(resources.getString(R.string.intent_extra_platform_id));
} else if (!applicationData.isNull(resources.getString(R.string.intent_extra_os))) {
os = (String) applicationData.get(resources.getString(R.string.intent_extra_os));
}
if (type != null && type.equalsIgnoreCase(resources.getString(R.string.intent_extra_enterprise))) {
if (os != null) {
if (os.equalsIgnoreCase(resources.getString(R.string.intent_extra_android))) {
appList.installApp(appUrl);
}
} else {
appList.installApp(appUrl);
}
} else if (type!= null && type.equalsIgnoreCase(resources.getString(R.string.intent_extra_market))) {
if (os != null) {
if (os.equalsIgnoreCase(resources.getString(R.string.intent_extra_android))) {
triggerGooglePlayApp(appUrl);
}
} else {
triggerGooglePlayApp(appUrl);
}
} else {
if (os != null) {
if (os.equalsIgnoreCase(resources.getString(R.string.intent_extra_android))) {
appList.installApp(appUrl);
}
} else {
appList.installApp(appUrl);
}
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
}
}

View File

@ -1,206 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.utils;
import org.wso2.mdm.agent.R;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.widget.EditText;
import android.widget.LinearLayout;
/**
* The CommonDialogUtils class contains the all dialog templates.
*/
public abstract class CommonDialogUtils {
/**
* Return an Alert Dialog with one button.
* @param context - The Activity which needs this alert dialog.
* @param message - The message in the alert.
* @param positiveBtnLabel - The label of the positive button.
* @param positiveClickListener- The onClickListener of the positive button.
* @return - The generated Alert Dialog.
*/
public static AlertDialog.Builder getAlertDialogWithOneButton(Context context,
String message,
String positiveBtnLabel,
DialogInterface.OnClickListener positiveClickListener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message).setPositiveButton(positiveBtnLabel, positiveClickListener);
return builder;
}
/**
* Return an Alert Dialog with two buttons.
* @param context - The Activity which needs this alert dialog.
* @param message - The message in the alert.
* @param positiveBtnLabel - The label of the positive button.
* @param negetiveBtnLabel - The label of the negative button.
* @param positiveClickListener- The onClickListener of the positive button.
* @param negativeClickListener- The onClickListener of the negative button.
* @return - The generated Alert Dialog.
*/
public static AlertDialog.Builder getAlertDialogWithTwoButton(Context context,
String message,
String positiveBtnLabel,
String negetiveBtnLabel,
DialogInterface.OnClickListener positiveClickListener,
DialogInterface.OnClickListener negativeClickListener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message).setPositiveButton(positiveBtnLabel, positiveClickListener)
.setNegativeButton(negetiveBtnLabel, negativeClickListener);
return builder;
}
/**
* Shows the Network unavailable message.
* @param context - The Activity where checking the network availability.
*/
public static void showNetworkUnavailableMessage(Context context) {
AlertDialog.Builder builder =
CommonDialogUtils.getAlertDialogWithOneButton(context,
context.getResources()
.getString(
R.string.error_network_unavailable),
context.getResources()
.getString(R.string.button_ok),
null
);
builder.show();
}
/**
* Return an Alert Dialog with two buttons and a title.
* @param context - The Activity which needs this alert dialog.
* @param title - The title of the message.
* @param message - The message in the alert.
* @param positiveBtnLabel - The label of the positive button.
* @param negetiveBtnLabel - The label of the negative button.
* @param positiveClickListener- The onClickListener of the positive button.
* @param negativeClickListener- The onClickListener of the negative button.
* @return - The generated Alert Dialog.
*/
public static AlertDialog.Builder getAlertDialogWithTwoButtonAndTitle(Context context,
String title,
String message,
String positiveBtnLabel,
String negetiveBtnLabel,
DialogInterface.OnClickListener positiveClickListener,
DialogInterface.OnClickListener negativeClickListener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message).setPositiveButton(positiveBtnLabel, positiveClickListener)
.setNegativeButton(negetiveBtnLabel, negativeClickListener);
return builder;
}
/**
* Returns an Alert Dialog with one button and title.
* @param context -The activity which need this alert.
* @param title -The alert title.
* @param message -The alert message.
* @param positiveBtnLabel -The positive button label.
* @param positiveClickListener -The positive button listener.
* @return - An alert dialog.
*/
public static AlertDialog.Builder getAlertDialogWithOneButtonAndTitle(Context context,
String title,
String message,
String positiveBtnLabel,
DialogInterface.OnClickListener positiveClickListener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message).setPositiveButton(positiveBtnLabel, positiveClickListener);
builder.show();
return builder;
}
/**
* Shows the ProgressDialog.
*
* @param context -The Activity which needs the ProgressDialog.
* @param title -The title.
* @param message -The message.
* @param cancelListener -The OnCancelListener.
* @return - A progress dialog.
*/
public static ProgressDialog showPrgressDialog(Context context, String title, String message,
OnCancelListener cancelListener) {
ProgressDialog progressDialog = ProgressDialog.show(context, title, message, true);
progressDialog.setCancelable(true);
progressDialog.setOnCancelListener(cancelListener);
return progressDialog;
}
/**
* Stops progressDialog.
* @param progressDialog -Progress dialog which needs to be stopped.
*/
public static void stopProgressDialog(ProgressDialog progressDialog) {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
/**
*
* Return an Alert Dialog with two buttons and a title.
* @param context - The Activity which needs this alert dialog.
* @param message - The message in the alert.
* @param positiveBtnLabel - The label of the positive button.
* @param negetiveBtnLabel - The label of the negative button.
* @param positiveClickListener- The onClickListener of the positive button.
* @param negativeClickListener- The onClickListener of the negative button.
* @param input - Edit text input.
* @return - The generated Alert Dialog.
*/
public static AlertDialog.Builder getAlertDialogWithTwoButtonAndEditView(Context context,
String message,
String positiveBtnLabel,
String negetiveBtnLabel,
DialogInterface.OnClickListener positiveClickListener,
DialogInterface.OnClickListener negativeClickListener,
EditText input) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message).setPositiveButton(positiveBtnLabel, positiveClickListener)
.setNegativeButton(negetiveBtnLabel, negativeClickListener);
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(params);
builder.setView(input);
return builder;
}
}

View File

@ -1,132 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.utils;
import org.json.JSONObject;
import org.wso2.mdm.agent.R;
import org.wso2.mdm.agent.proxy.APIController;
import org.wso2.mdm.agent.proxy.interfaces.APIResultCallBack;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import org.wso2.mdm.agent.proxy.beans.EndPointInfo;
import org.wso2.mdm.agent.services.AgentDeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class CommonUtils {
public static String TAG = CommonUtils.class.getSimpleName();
/**
* Calls the secured API.
* @param context -The Activity which calls an API.
* @param serverUrl -The server url.
* @param endpoint -The API endpoint.
* @param apiVersion -The API version.
* @param methodType -The method type.
* @param apiResultCallBack -The API result call back object.
* @param requestCode -The request code.
*/
public static void callSecuredAPI(Context context, String endpoint, HTTP_METHODS methodType,
JSONObject requestParams,
APIResultCallBack apiResultCallBack, int requestCode) {
EndPointInfo apiUtilities = new EndPointInfo();
apiUtilities.setEndPoint(endpoint);
apiUtilities.setHttpMethod(methodType);
if (requestParams != null) {
apiUtilities.setRequestParams(requestParams);
}
APIController apiController = new APIController();
String clientKey =
Preference.getString(context,
context.getResources()
.getString(R.string.shared_pref_client_id)
);
String clientSecret =
Preference.getString(context,
context.getResources()
.getString(R.string.shared_pref_client_secret)
);
if (clientKey!=null && !clientKey.isEmpty() && !clientSecret.isEmpty()) {
apiController.setClientDetails(clientKey, clientSecret);
}
apiController.invokeAPI(apiUtilities, apiResultCallBack, requestCode,
context.getApplicationContext());
}
/**
* Clear application data.
* @param context - Application context.
*/
public static void clearAppData(Context context) {
DevicePolicyManager devicePolicyManager;
ComponentName demoDeviceAdmin;
Resources resources = context.getResources();
devicePolicyManager =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
demoDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
SharedPreferences mainPref =
context.getSharedPreferences(context.getResources()
.getString(R.string.shared_pref_package),
Context.MODE_PRIVATE
);
Editor editor = mainPref.edit();
editor.putString(context.getResources().getString(R.string.shared_pref_policy),
resources.getString(R.string.shared_pref_default_string));
editor.putString(context.getResources().getString(R.string.shared_pref_isagreed),
resources.getString(R.string.shared_pref_device_active));
editor.putString(context.getResources().getString(R.string.shared_pref_regId),
resources.getString(R.string.shared_pref_default_string));
editor.putString(context.getResources().getString(R.string.shared_pref_registered),
resources.getString(R.string.shared_pref_device_active));
editor.putString(context.getResources().getString(R.string.shared_pref_ip),
resources.getString(R.string.shared_pref_default_string));
editor.putString(context.getResources().getString(R.string.shared_pref_sender_id),
resources.getString(R.string.shared_pref_default_string));
editor.putString(context.getResources().getString(R.string.shared_pref_eula),
resources.getString(R.string.shared_pref_default_string));
editor.commit();
devicePolicyManager.removeActiveAdmin(demoDeviceAdmin);
}
/**
* Returns network availability status.
* @param context - Application context.
* @return - Network availability status.
*/
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if (info == null) {
return false;
}
return info.isConnected();
}
}

View File

@ -1,135 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.utils;
public class Constants {
public static final boolean DEBUG_MODE_ENABLED = true;
public static final boolean LOCAL_NOTIFICATIONS_ENABLED = true;
public static final boolean GCM_ENABLED = false;
public static final String SERVER_PORT = "9763";
public static final String SERVER_PROTOCOL = "http://";
public static final String API_VERSION = "1.0.0";
public static final String API_SERVER_PORT = "9763";
public static final String SERVER_APP_ENDPOINT = "/mdm-android-agent/";
public static final String SERVER_AUTHENTICATION_ENDPOINT = "register/authenticate/device";
public static final String LICENSE_ENDPOINT = "/license/" + API_VERSION;
public static final String REGISTER_ENDPOINT = "/enroll/" + API_VERSION;
public static final String OAUTH_ENDPOINT = "/oauth2/token";
public static final String SENDER_ID_ENDPOINT = "devices/sender_id/";
public static final String IS_REGISTERED_ENDPOINT = "devices/isregistered/";
public static final String UNREGISTER_ENDPOINT = "devices/unregister/";
public static final String NOTIFICATION_ENDPOINT = "/operation/" + API_VERSION;
public static final String GOOGLE_PLAY_APP_URI = "market://details?id=";
public static final String TRUSTSTORE_PASSWORD = "wso2carbon";
public static final String EULA_TITLE = "POLICY AGREEMENT";
public static final String EULA_TEXT = "Test policy agreement.";
public static final String EMPTY_STRING = "";
public static final String NULL_STRING = "null";
public static final String STATUS_KEY = "status";
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String STATUS = "status";
public static final String RESPONSE = "response";
public static final String PROPERTIES = "properties";
public static final String CODE = "code";
public static final String LOCAL = "LOCAL";
public static final String LOG_FILE = "wso2log.txt";
/**
* Request codes.
*/
public static final int REGISTER_REQUEST_CODE = 300;
public static final int IS_REGISTERED_REQUEST_CODE = 301;
public static final int SENDER_ID_REQUEST_CODE = 303;
public static final int LICENSE_REQUEST_CODE = 304;
public static final int UNREGISTER_REQUEST_CODE = 305;
public static final int NOTIFICATION_REQUEST_CODE = 306;
/**
* Google API project id registered to use GCM.
*/
public static final String SENDER_ID = "";
/**
* Tag used on log messages.
*/
public static final String TAG = "WSO2EMM";
/**
* Intent used to display a message in the screen.
*/
public static final String DISPLAY_MESSAGE_ACTION =
"com.google.android.gcm.demo.app.DISPLAY_MESSAGE";
/**
* Intent's extra that contains the message to be displayed.
*/
public static final String EXTRA_MESSAGE = "message";
public static final int MESSAGE_MODE_GCM = 1;
public static final int MESSAGE_MODE_SMS = 2;
public static final int MESSAGE_MODE_LOCAL = 3;
/**
* Status codes
*/
public static final String REQUEST_SUCCESSFUL = "200";
public static final String REGISTERATION_SUCCESSFUL = "201";
public static final String REQUEST_FAILED = "500";
public static final String AUTHENTICATION_FAILED = "400";
public static final String UNAUTHORIZED_ACCESS = "401";
public static final String NOT_FOUND = "404";
public static final String INTERNAL_SERVER_ERROR = "500";
/**
* Operation IDs
*/
public static final String OPERATION_DEVICE_INFO = "500A";
public static final String OPERATION_DEVICE_LOCATION = "501A";
public static final String OPERATION_GET_APPLICATION_LIST = "502A";
public static final String OPERATION_LOCK_DEVICE = "DEVICE_LOCK";
public static final String OPERATION_WIPE_DATA = "504A";
public static final String OPERATION_CLEAR_PASSWORD = "505A";
public static final String OPERATION_NOTIFICATION = "506A";
public static final String OPERATION_WIFI = "507A";
public static final String OPERATION_DISABLE_CAMERA = "508A";
public static final String OPERATION_INSTALL_APPLICATION = "509A";
public static final String OPERATION_INSTALL_APPLICATION_BUNDLE = "509B";
public static final String OPERATION_UNINSTALL_APPLICATION = "510A";
public static final String OPERATION_ENCRYPT_STORAGE = "511A";
public static final String OPERATION_RING = "512A";
public static final String OPERATION_MUTE = "513A";
public static final String OPERATION_WEBCLIP = "518A";
public static final String OPERATION_PASSWORD_POLICY = "519A";
public static final String OPERATION_EMAIL_CONFIGURATION = "520A";
public static final String OPERATION_INSTALL_GOOGLE_APP = "522A";
public static final String OPERATION_CHANGE_LOCK_CODE = "526A";
public static final String OPERATION_ENTERPRISE_WIPE_DATA = "527A";
public static final String OPERATION_POLICY_BUNDLE = "500P";
public static final String OPERATION_POLICY_MONITOR = "501P";
public static final String OPERATION_BLACKLIST_APPS = "528B";
public static final String OPERATION_POLICY_REVOKE = "502P";
}

View File

@ -1,94 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import org.wso2.mdm.agent.R;
/**
* Data retrieval and saving to shared preferences is done here.
*/
public class Preference {
private static final int DEFAULT_INDEX = 0;
/**
* Put data to shared preferences in private mode.
* @param context - The context of activity which is requesting to put data.
* @param key - Used to identify the value.
* @param value - The actual value to be saved.
*/
public static void putString(Context context, String key, String value) {
SharedPreferences mainPref =
context.getSharedPreferences(context.getResources()
.getString(R.string.shared_pref_package),
Context.MODE_PRIVATE
);
Editor editor = mainPref.edit();
editor.putString(key, value);
editor.commit();
}
/**
* Retrieve data from shared preferences in private mode.
* @param context - The context of activity which is requesting to put data.
* @param key - Used to identify the value to to be retrieved.
*/
public static String getString(Context context, String key) {
SharedPreferences mainPref =
context.getSharedPreferences(context.getResources()
.getString(R.string.shared_pref_package),
Context.MODE_PRIVATE
);
return mainPref.getString(key, null);
}
/**
* Put data to shared preferences in private mode.
* @param context - The context of activity which is requesting to put data.
* @param key - Used to identify the value.
* @param value - The actual value to be saved.
*/
public static void putFloat(Context context, String key, float value) {
SharedPreferences mainPref =
context.getSharedPreferences(context.getResources()
.getString(R.string.shared_pref_package),
Context.MODE_PRIVATE
);
Editor editor = mainPref.edit();
editor.putFloat(key, value);
editor.commit();
}
/**
* Retrieve data from shared preferences in private mode.
* @param context - The context of activity which is requesting to put data.
* @param key - Used to identify the value to to be retrieved.
*/
public static float getFloat(Context context, String key) {
SharedPreferences mainPref =
context.getSharedPreferences(context.getResources()
.getString(R.string.shared_pref_package),
Context.MODE_PRIVATE
);
return mainPref.getFloat(key, DEFAULT_INDEX);
}
}

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.utils;
import org.wso2.mdm.agent.R;
/**
* Describes the errors and their relevant error messages.
* In order to internationalize the message in the res.
*/
public enum Response {
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);
private final boolean code;
private final int descriptionResourceID;
private Response(boolean code, int description) {
this.code = code;
this.descriptionResourceID = description;
}
public int getDescriptionResourceID() {
return descriptionResourceID;
}
public boolean getCode() {
return code;
}
}

View File

@ -1,78 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.util.Log;
public class StreamHandler {
/**
* Close a ByteArrayOutputStream passed in.
*
* @param stream
* - ByteArrayOutputStream to be closed.
*/
public static void closeOutputStream(OutputStream stream, String tag) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
Log.e(tag, "Exception occured when closing ByteArrayOutputStream." + e);
}
}
}
/**
* Close a InputStream passed in.
*
* @param stream
* - InputStream to be closed.
*/
public static void closeInputStream(InputStream stream, String tag) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
Log.e(tag, "Exception occured when closing InputStream." + e);
}
}
}
/**
* Close a InputStream passed in.
*
* @param stream
* - InputStream to be closed.
*/
public static void closeBufferedReader(BufferedReader stream, String tag) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
Log.e(tag, "Exception occured when closing BufferedReader." + e);
}
}
}
}

View File

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<lint>
</lint>

View File

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon</groupId>
<artifactId>idp-proxy</artifactId>
<packaging>apklib</packaging>
<version>1.0.0</version>
<name>IDPProxy</name>
<dependencies>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>${android.lib.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons.codec.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
<properties>
<android.lib.version>5.0.1_r2</android.lib.version>
<commons.codec.version>1.9</commons.codec.version>
</properties>
</project>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.wso2.mdm.agent.proxy"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
</application>
</manifest>

View File

@ -1,113 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import org.wso2.mdm.agent.proxy.beans.EndPointInfo;
import org.wso2.mdm.agent.proxy.beans.Token;
import org.wso2.mdm.agent.proxy.interfaces.APIResultCallBack;
import org.wso2.mdm.agent.proxy.interfaces.TokenCallBack;
import org.wso2.mdm.agent.proxy.utils.ServerUtilities;
import java.util.HashMap;
import java.util.Map;
public class APIController implements TokenCallBack {
private static final String TAG = "APIController";
private static Token token;
private static String clientKey, clientSecret;
private APIResultCallBack apiResultCall;
private EndPointInfo apiUtilitiesCurrent;
public void setClientDetails(String clientKey, String clientSecret) {
APIController.clientKey = clientKey;
APIController.clientSecret = clientSecret;
}
/**
* Invoking an API using retrieved token.
*
* @param apiUtilities - Server and API end point information.
* @param apiResultCallBack - API result callback data.
* @param requestCode - Request code to avoid response complications.
* @param context - Application context.
*/
public void invokeAPI(EndPointInfo apiUtilities, APIResultCallBack apiResultCallBack,
int requestCode, Context context) {
apiResultCall = apiResultCallBack;
apiUtilitiesCurrent = apiUtilities;
if (IdentityProxy.getInstance().getContext() == null) {
IdentityProxy.getInstance().setContext(context);
}
IdentityProxy.getInstance().setRequestCode(requestCode);
IdentityProxy.getInstance().requestToken(IdentityProxy.getInstance().getContext(), this,
APIController.clientKey,
APIController.clientSecret);
}
@Override
public void onReceiveTokenResult(Token token, String status) {
APIController.token = token;
new NetworkCallTask(apiResultCall).execute(apiUtilitiesCurrent);
}
/**
* AsyncTask to contact server and access the API with retrieved token.
*/
private class NetworkCallTask extends AsyncTask<EndPointInfo, Void, Map<String, String>> {
APIResultCallBack apiResultCallBack;
public NetworkCallTask(APIResultCallBack apiResultCallBack) {
this.apiResultCallBack = apiResultCallBack;
}
@Override
protected Map<String, String> doInBackground(EndPointInfo... params) {
EndPointInfo apiUtilities = params[0];
Map<String, String> responseParams = null;
String accessToken = token.getAccessToken();
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
headers.put("Accept", "*/*");
headers.put("User-Agent", "Mozilla/5.0 ( compatible ), Android");
headers.put("Authorization", "Bearer " + accessToken);
try {
responseParams = ServerUtilities.postData(apiUtilities, headers);
} catch (IDPTokenManagerException e) {
Log.e(TAG, "Failed to contact server." + e);
}
return responseParams;
}
@Override
protected void onPostExecute(Map<String, String> result) {
apiResultCallBack.onReceiveAPIResult(result, IdentityProxy.getInstance()
.getRequestCode());
}
}
}

View File

@ -1,167 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.util.Log;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.mdm.agent.proxy.beans.EndPointInfo;
import org.wso2.mdm.agent.proxy.beans.CredentialInfo;
import org.wso2.mdm.agent.proxy.beans.Token;
import org.wso2.mdm.agent.proxy.interfaces.CallBack;
import org.wso2.mdm.agent.proxy.utils.Constants;
import org.wso2.mdm.agent.proxy.utils.ServerUtilities;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* After receiving authorization code client application can use this class to
* obtain access token
*/
public class AccessTokenHandler extends Activity {
private static final String TAG = "AccessTokenHandler";
private static final String USERNAME_LABEL = "username";
private static final String PASSWORD_LABEL = "password";
private static final String COLON = ":";
private static final DateFormat dateFormat =
new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.getDefault());
private CredentialInfo info;
public AccessTokenHandler(CredentialInfo info, CallBack callBack) {
this.info = info;
}
public void obtainAccessToken() {
new NetworkCallTask().execute();
}
/**
* AsyncTask to contact authorization server and get access token, refresh
* token as a result
*/
private class NetworkCallTask extends AsyncTask<Void, Void, String> {
private String response = null;
private String responseCode = null;
@Override
protected String doInBackground(Void... arg0) {
Map<String, String> request_params = new HashMap<String, String>();
request_params.put(Constants.GRANT_TYPE, Constants.GRANT_TYPE_PASSWORD);
request_params.put(USERNAME_LABEL, info.getUsername());
request_params.put(PASSWORD_LABEL, info.getPassword());
EndPointInfo apiUtilities = new EndPointInfo();
apiUtilities.setEndPoint(info.getTokenEndPoint());
apiUtilities.setHttpMethod(HTTP_METHODS.POST);
apiUtilities.setRequestParamsMap(request_params);
byte[] credentials = Base64.encodeBase64((info.getClientID() + COLON +
info.getClientSecret()).getBytes());
String encodedCredentials = new String(credentials);
Map<String, String> headers = new HashMap<String, String>();
String authorizationString = Constants.AUTHORIZATION_MODE + encodedCredentials;
headers.put(Constants.AUTHORIZATION_HEADER, authorizationString);
headers.put(Constants.CONTENT_TYPE_HEADER, Constants.DEFAULT_CONTENT_TYPE);
Map<String, String> responseParams = null;
try {
responseParams = ServerUtilities.postDataAPI(apiUtilities, headers);
response = responseParams.get(Constants.SERVER_RESPONSE_BODY);
responseCode = responseParams.get(Constants.SERVER_RESPONSE_STATUS);
} catch (IDPTokenManagerException e) {
Log.e(TAG, "Failed to contact server." + e);
}
return response;
}
@SuppressLint("SimpleDateFormat")
@Override
protected void onPostExecute(String result) {
String refreshToken = null;
String accessToken = null;
int timeToExpireSecond = 3000;
try {
IdentityProxy identityProxy = IdentityProxy.getInstance();
if (responseCode != null && responseCode.equals(Constants.REQUEST_SUCCESSFUL)) {
JSONObject response = new JSONObject(result);
try {
accessToken = response.getString(Constants.ACCESS_TOKEN);
refreshToken = response.getString(Constants.REFRESH_TOKEN);
timeToExpireSecond =
Integer.parseInt(response.getString(Constants.EXPIRE_LABEL));
Token token = new Token();
Date date = new Date();
String currentDate = dateFormat.format(date);
token.setDate(currentDate);
token.setRefreshToken(refreshToken);
token.setAccessToken(accessToken);
token.setExpired(false);
SharedPreferences mainPref =
IdentityProxy.getInstance()
.getContext()
.getSharedPreferences(Constants.APPLICATION_PACKAGE,
Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
editor.putString(Constants.ACCESS_TOKEN, accessToken);
editor.putString(Constants.REFRESH_TOKEN, refreshToken);
editor.putString(USERNAME_LABEL, info.getUsername());
long expiresIN = date.getTime() + (timeToExpireSecond * 1000);
Date expireDate = new Date(expiresIN);
String strDate = dateFormat.format(expireDate);
token.setDate(strDate);
editor.putString(Constants.DATE_LABEL, strDate);
editor.commit();
identityProxy.receiveAccessToken(responseCode, Constants.SUCCESS_RESPONSE,
token);
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON format." + e);
}
} else if (responseCode != null) {
if (Constants.INTERNAL_SERVER_ERROR.equals(responseCode)) {
identityProxy.receiveAccessToken(responseCode, result, null);
} else {
JSONObject mainObject = new JSONObject(result);
String errorDescription =
mainObject.getString(Constants.ERROR_DESCRIPTION_LABEL);
identityProxy.receiveAccessToken(responseCode, errorDescription, null);
}
}
} catch (JSONException e) {
Log.e(TAG, "Invalid JSON." + e);
}
}
}
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy;
/**
* Custom exception class for IDP plug-in related exceptions.
*/
public class IDPTokenManagerException extends Exception {
private static final long serialVersionUID = 1L;
private String errorMessage;
public IDPTokenManagerException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public IDPTokenManagerException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public IDPTokenManagerException(String msg) {
super(msg);
setErrorMessage(msg);
}
public IDPTokenManagerException() {
super();
}
public IDPTokenManagerException(Throwable cause) {
super(cause);
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}

View File

@ -1,173 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import org.wso2.mdm.agent.proxy.beans.CredentialInfo;
import org.wso2.mdm.agent.proxy.beans.Token;
import org.wso2.mdm.agent.proxy.interfaces.APIAccessCallBack;
import org.wso2.mdm.agent.proxy.interfaces.CallBack;
import org.wso2.mdm.agent.proxy.interfaces.TokenCallBack;
import org.wso2.mdm.agent.proxy.utils.Constants;
import org.wso2.mdm.agent.proxy.utils.ServerUtilities;
/**
* client application specific data
*/
public class IdentityProxy implements CallBack {
public final static boolean initiated = false;
public static String clientID;
public static String clientSecret;
private static String TAG = "IdentityProxy";
private static Token token = null;
private static IdentityProxy identityProxy = new IdentityProxy();
private static Context context;
private static String accessTokenURL;
private APIAccessCallBack apiAccessCallBack;
private TokenCallBack callback;
private int requestCode = 0;
private IdentityProxy() {
}
public static synchronized IdentityProxy getInstance() {
return identityProxy;
}
public int getRequestCode() {
return requestCode;
}
public void setRequestCode(int requestCode) {
this.requestCode = requestCode;
}
public String getAccessTokenURL() {
return accessTokenURL;
}
public void setAccessTokenURL(String accessTokenURL) {
IdentityProxy.accessTokenURL = accessTokenURL;
}
@Override
public void receiveAccessToken(String status, String message, Token token) {
if (token != null) {
Log.d(TAG, token.getAccessToken());
Log.d(TAG, token.getRefreshToken());
}
IdentityProxy.token = token;
apiAccessCallBack.onAPIAccessRecive(status);
}
@Override
public void receiveNewAccessToken(String status, String message, Token token) {
IdentityProxy.token = token;
callback.onReceiveTokenResult(token, status);
}
/**
* Initializing the IDP plugin and obrtaining the access token.
*
* @param info - Includes token end point and Oauth app credentials.
* @param apiAccessCallBack - Callback when API access happens.
* @param appContext - Application context.
*/
public void init(CredentialInfo info, APIAccessCallBack apiAccessCallBack, Context appContext) {
IdentityProxy.clientID = info.getClientID();
IdentityProxy.clientSecret = info.getClientSecret();
this.apiAccessCallBack = apiAccessCallBack;
context = appContext;
SharedPreferences mainPref = context.getSharedPreferences(Constants.APPLICATION_PACKAGE
, Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
editor.putString(Constants.CLIENT_ID, clientID);
editor.putString(Constants.CLIENT_SECRET, clientSecret);
editor.putString(Constants.TOKEN_ENDPOINT, info.getTokenEndPoint());
editor.commit();
setAccessTokenURL(info.getTokenEndPoint());
AccessTokenHandler accessTokenHandler = new AccessTokenHandler(info, this);
accessTokenHandler.obtainAccessToken();
}
public void requestToken(Context contextt, TokenCallBack call, String clientID,
String clientSecret) {
context = contextt;
callback = call;
IdentityProxy.clientID = clientID;
IdentityProxy.clientSecret = clientSecret;
if (token == null) {
validateStoredToken();
} else {
boolean isExpired = ServerUtilities.isValid(token.getDate());
if (!isExpired) {
IdentityProxy.getInstance().receiveNewAccessToken(Constants.REQUEST_SUCCESSFUL,
"success", token);
} else {
validateStoredToken();
}
}
}
private void validateStoredToken() {
SharedPreferences mainPref = context.getSharedPreferences(Constants.APPLICATION_PACKAGE,
Context.MODE_PRIVATE);
String refreshToken = mainPref.getString(Constants.REFRESH_TOKEN, null).toString();
String accessToken = mainPref.getString(Constants.ACCESS_TOKEN, null).toString();
String date = mainPref.getString(Constants.DATE_LABEL, null).toString();
String endPoint = mainPref.getString(Constants.TOKEN_ENDPOINT, null).toString();
setAccessTokenURL(endPoint);
if (!refreshToken.isEmpty()) {
token = new Token();
token.setDate(date);
token.setRefreshToken(refreshToken);
token.setAccessToken(accessToken);
boolean isExpired = ServerUtilities.isValid(token.getDate());
if (!isExpired) {
IdentityProxy.getInstance().receiveNewAccessToken(Constants.REQUEST_SUCCESSFUL,
Constants.SUCCESS_RESPONSE,
token);
} else {
refreshToken();
}
} else {
IdentityProxy.getInstance().receiveNewAccessToken(Constants.ACCESS_FAILURE,
Constants.FAILURE_RESPONSE, token);
}
}
public void refreshToken() {
RefreshTokenHandler refreshTokenHandler = new RefreshTokenHandler(token);
refreshTokenHandler.obtainNewAccessToken();
}
public Context getContext() {
return context;
}
public void setContext(Context context) {
IdentityProxy.context = context;
}
}

View File

@ -1,153 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.util.Log;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.mdm.agent.proxy.beans.EndPointInfo;
import org.wso2.mdm.agent.proxy.beans.Token;
import org.wso2.mdm.agent.proxy.utils.Constants;
import org.wso2.mdm.agent.proxy.utils.ServerUtilities;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* Getting new access token and refresh token after access token expiration
*/
public class RefreshTokenHandler {
private static final String TAG = "RefreshTokenHandler";
private static final String SCOPE_LABEL = "scope";
private static final String PRODUCTION_LABEL = "PRODUCTION";
private static final DateFormat dateFormat =
new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.getDefault());
private static final String COLON = ":";
private Token token;
public RefreshTokenHandler(Token token) {
this.token = token;
}
public void obtainNewAccessToken() {
new NetworkCallTask().execute();
}
private class NetworkCallTask extends AsyncTask<String, Void, String> {
private String responseCode = null;
@Override
protected String doInBackground(String... params) {
String response = null;
Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put(Constants.GRANT_TYPE, Constants.REFRESH_TOKEN);
requestParams.put(Constants.REFRESH_TOKEN, token.getRefreshToken());
requestParams.put(SCOPE_LABEL, PRODUCTION_LABEL);
EndPointInfo apiUtilities = new EndPointInfo();
apiUtilities.setEndPoint(IdentityProxy.getInstance().getAccessTokenURL());
apiUtilities.setHttpMethod(HTTP_METHODS.POST);
apiUtilities.setRequestParamsMap(requestParams);
byte[] credentials = Base64.encodeBase64((IdentityProxy.clientID + COLON +
IdentityProxy.clientSecret).getBytes());
String encodedCredentials = new String(credentials);
Map<String, String> headers = new HashMap<String, String>();
String authorizationString = Constants.AUTHORIZATION_MODE + encodedCredentials;
headers.put(Constants.AUTHORIZATION_HEADER, authorizationString);
headers.put(Constants.CONTENT_TYPE_HEADER, Constants.DEFAULT_CONTENT_TYPE);
Map<String, String> responseParams = null;
try {
responseParams = ServerUtilities.postDataAPI(apiUtilities, headers);
} catch (IDPTokenManagerException e) {
Log.e(TAG, "Failed to contact server." + e);
}
response = responseParams.get(Constants.SERVER_RESPONSE_BODY);
responseCode = responseParams.get(Constants.SERVER_RESPONSE_STATUS);
return response;
}
@SuppressLint("SimpleDateFormat")
@Override
protected void onPostExecute(String result) {
String refreshToken = null;
String accessToken = null;
int timeToExpireSecond = 3000;
IdentityProxy identityProxy = IdentityProxy.getInstance();
try {
JSONObject response = new JSONObject(result);
if (responseCode != null && responseCode.equals(Constants.REQUEST_SUCCESSFUL)) {
refreshToken = response.getString(Constants.REFRESH_TOKEN);
accessToken = response.getString(Constants.ACCESS_TOKEN);
timeToExpireSecond =
Integer.parseInt(response.getString(Constants.EXPIRE_LABEL));
token.setRefreshToken(refreshToken);
token.setAccessToken(accessToken);
SharedPreferences mainPref =
IdentityProxy.getInstance()
.getContext()
.getSharedPreferences(Constants.APPLICATION_PACKAGE,
Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
editor.putString(Constants.REFRESH_TOKEN, refreshToken);
editor.putString(Constants.ACCESS_TOKEN, accessToken);
Date date = new Date();
long expiresIN = date.getTime() + (timeToExpireSecond * 1000);
Date expireDate = new Date(expiresIN);
String strDate = dateFormat.format(expireDate);
token.setDate(strDate);
editor.putString(Constants.DATE_LABEL, strDate);
editor.commit();
identityProxy
.receiveNewAccessToken(responseCode, Constants.SUCCESS_RESPONSE, token);
} else if (responseCode != null) {
JSONObject responseBody = new JSONObject(result);
String errorDescription =
responseBody.getString(Constants.ERROR_DESCRIPTION_LABEL);
identityProxy.receiveNewAccessToken(responseCode, errorDescription, token);
}
} catch (JSONException e) {
identityProxy.receiveNewAccessToken(responseCode, null, token);
Log.e(TAG, "Invalid JSON." + e);
}
}
}
}

View File

@ -1,67 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.beans;
public class CredentialInfo {
private String username = null;
private String password = null;
private String clientID = null;
private String clientSecret = null;
private String tokenEndPoint = null;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getClientID() {
return clientID;
}
public void setClientID(String clientID) {
this.clientID = clientID;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getTokenEndPoint() {
return tokenEndPoint;
}
public void setTokenEndPoint(String tokenEndPoint) {
this.tokenEndPoint = tokenEndPoint;
}
}

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.beans;
import org.json.JSONObject;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import java.util.Map;
public class EndPointInfo {
private HTTP_METHODS httpMethod;
private String endPoint;
private JSONObject requestParams;
private Map<String, String> requestParamsMap;
public Map<String, String> getRequestParamsMap() {
return requestParamsMap;
}
public void setRequestParamsMap(Map<String, String> requestParams) {
this.requestParamsMap = requestParams;
}
public JSONObject getRequestParams() {
return requestParams;
}
public void setRequestParams(JSONObject requestParams) {
this.requestParams = requestParams;
}
public HTTP_METHODS getHttpMethod() {
return httpMethod;
}
public void setHttpMethod(HTTP_METHODS httpMethod) {
this.httpMethod = httpMethod;
}
public String getEndPoint() {
return endPoint;
}
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}
}

View File

@ -1,73 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.beans;
import org.wso2.mdm.agent.proxy.utils.ServerUtilities;
import java.util.Date;
/**
* Persists refresh token to obtain new access token and id token to retrieve
* login user claims
*/
public final class Token {
private String refreshToken = null;
private String idToken = null;
private String accessToken = null;
private Date receivedDate = null;
@SuppressWarnings("unused")
private boolean expired = false;
public Date getDate() {
return receivedDate;
}
public void setDate(String date) {
receivedDate = ServerUtilities.convertDate(date);
}
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getIdToken() {
return idToken;
}
public void setIdToken(String id_Token) {
idToken = id_Token;
}
public String getRefreshToken() {
return refreshToken;
}
public void setRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
}
public void setExpired(boolean expired) {
this.expired = expired;
}
}

View File

@ -1,27 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.interfaces;
/**
* This interface handles API access callback when the application
* is able to receive the access token by passing necessary credentials. Applications
* can implement this when retrieving tokens on authentication.
*/
public interface APIAccessCallBack {
void onAPIAccessRecive(String status);
}

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.interfaces;
import java.util.Map;
/**
* This interface handles API result callback when the application
* is able to receive the API results by passing access token. Applications
* can implement this when API access is required.
*/
public interface APIResultCallBack {
void onReceiveAPIResult(Map<String, String> result, int requestCode);
}

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.interfaces;
import org.wso2.mdm.agent.proxy.beans.Token;
/**
* This interface handles token callback when the application
* is able to receive the access token from the app local storage or from the server.
* Applications can implement this when it requires access token.
*/
public interface CallBack {
/**
* Get access token stored in the app preferences.
*
* @param status - Status code.
* @param message - Success/Error message.
* @param token - Token retrieved.
*/
void receiveAccessToken(String status, String message, Token token);
/**
* Get a new access token from the server.
*
* @param status - Status code.
* @param message - Success/Error message.
* @param token - Token retrieved.
*/
void receiveNewAccessToken(String status, String message, Token token);
}

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.interfaces;
import org.wso2.mdm.agent.proxy.beans.Token;
/**
* This interface handles token callback when the application
* is able to receive the access token. Applications
* can implement this when they retrieve tokens.
*/
public interface TokenCallBack {
void onReceiveTokenResult(Token token, String status);
}

View File

@ -1,57 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.utils;
public class Constants {
public static final String SERVER_PROTOCOL = "http://";
public static final String TRUSTSTORE_PASSWORD = "wso2carbon";
public final static int ACCESS_TOKEN_AGE = 3000;
public final static String GRANT_TYPE = "grant_type";
public final static String GRANT_TYPE_PASSWORD = "password";
public final static String GRANT_TYPE_AUTHORIZATION_CODE = "authorization_code";
public final static String GRANT_TYPE_REFRESH_TOKEN = "refresh_token";
public final static String AUTHORIZATION_CODE = "code";
public final static String AUTHORIZATION_MODE = "Basic ";
public final static String AUTHORIZATION_HEADER = "Authorization";
public final static String CONTENT_TYPE_HEADER = "Content-Type";
public final static String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded";
public final static String REDIRECT_URL = "redirect_uri";
public final static String SCOPE = "scope";
public final static String OPENID = "openid";
public static final String DATE_LABEL = "date";
public final static String SERVER_RESPONSE_BODY = "response";
public final static String SERVER_RESPONSE_STATUS = "status";
public static final String SUCCESS_RESPONSE = "success";
public static final String FAILURE_RESPONSE = "fail";
public final static String REFRESH_TOKEN = "refresh_token";
public final static String ACCESS_TOKEN = "access_token";
public final static String EXPIRE_LABEL = "expires_in";
public static final String ERROR_LABEL = "error";
public static final String ERROR_DESCRIPTION_LABEL = "error_description";
public final static String APPLICATION_PACKAGE = "com.mdm";
public final static String ID_TOKEN = "id_token";
public final static String CLIENT_ID = "client_id";
public final static String CLIENT_SECRET = "client_secret";
public final static String TOKEN_ENDPOINT = "token_endpoint";
public static enum HTTP_METHODS{GET, POST};
public static final String INTERNAL_SERVER_ERROR = "500";
public static final String ACCESS_FAILURE = "400";
public static final String REQUEST_SUCCESSFUL = "200";
}

View File

@ -1,364 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.utils;
import android.util.Log;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
import org.json.JSONObject;
import org.wso2.mdm.agent.proxy.IDPTokenManagerException;
import org.wso2.mdm.agent.proxy.IdentityProxy;
import org.wso2.mdm.agent.proxy.R;
import org.wso2.mdm.agent.proxy.beans.EndPointInfo;
import org.wso2.mdm.agent.proxy.utils.Constants.HTTP_METHODS;
import java.io.*;
import java.security.*;
import java.security.cert.CertificateException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
/**
* Handle network communication between SDK and authorization server
*/
public class ServerUtilities {
private final static String TAG = "ServerUtilities";
private static final DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss",
Locale.getDefault());
/**
* Validate the token expiration date.
*
* @param expirationDate - Token expiration date.
* @return - Token status.
*/
public static boolean isValid(Date expirationDate) {
Date currentDate = new Date();
String formattedDate = dateFormat.format(currentDate);
currentDate = convertDate(formattedDate);
boolean isExpired = currentDate.after(expirationDate);
boolean isEqual = currentDate.equals(expirationDate);
if (isExpired == true || isEqual == true) {
return true;
}
return false;
}
/**
* Convert the date to the standard format.
*
* @param date - Date as a string.
* @return - Formatted date.
*/
public static Date convertDate(String date) {
Date receivedDate = null;
try {
receivedDate = dateFormat.parse(date);
} catch (ParseException e) {
Log.e(TAG, "Invalid date format." + e);
}
return receivedDate;
}
public static String buildPayload(Map<String, String> params) {
StringBuilder bodyBuilder = new StringBuilder();
Iterator<Entry<String, String>> iterator = params.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, String> param = iterator.next();
bodyBuilder.append(param.getKey()).append('=').append(param.getValue());
if (iterator.hasNext()) {
bodyBuilder.append('&');
}
}
return bodyBuilder.toString();
}
public static HttpRequestBase buildHeaders(HttpRequestBase httpRequestBase,
Map<String, String> headers, HTTP_METHODS httpMethod) {
Iterator<Entry<String, String>> iterator = headers.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, String> header = iterator.next();
httpRequestBase.setHeader(header.getKey(), header.getValue());
}
return httpRequestBase;
}
public static Map<String, String> postData(EndPointInfo apiUtilities,
Map<String, String> headers)
throws IDPTokenManagerException {
HTTP_METHODS httpMethod = apiUtilities.getHttpMethod();
String url = apiUtilities.getEndPoint();
JSONObject params = apiUtilities.getRequestParams();
Map<String, String> responseParams = new HashMap<String, String>();
switch (httpMethod) {
case GET:
responseParams = sendGetRequest(url, params, headers);
break;
case POST:
responseParams = sendPostRequest(url, params, headers);
break;
}
return responseParams;
}
public static Map<String, String> sendGetRequest(String url, JSONObject params, Map<String, String> headers) throws IDPTokenManagerException{
HttpGet httpGet = new HttpGet(url);
HttpGet httpGetWithHeaders = (HttpGet) buildHeaders(httpGet, headers, HTTP_METHODS.GET);
HttpClient httpClient = getCertifiedHttpClient();
Map<String, String> responseParams = new HashMap<String, String>();
try {
HttpResponse response = httpClient.execute(httpGetWithHeaders);
responseParams.put(Constants.SERVER_RESPONSE_BODY, getResponseBody(response));
responseParams.put(Constants.SERVER_RESPONSE_STATUS,
String.valueOf(response.getStatusLine().getStatusCode()));
} catch (ClientProtocolException e) {
throw new IDPTokenManagerException("Invalid client protocol.", e);
} catch (IOException e) {
responseParams.put(Constants.SERVER_RESPONSE_BODY, "Internal Server Error");
responseParams.put(Constants.SERVER_RESPONSE_STATUS,
Constants.INTERNAL_SERVER_ERROR);
throw new IDPTokenManagerException("Server connectivity failure.", e);
}
return responseParams;
}
public static Map<String, String> sendPostRequest(String url, JSONObject params, Map<String, String> headers) throws IDPTokenManagerException{
HttpPost httpPost = new HttpPost(url);
HttpClient httpClient = getCertifiedHttpClient();
Map<String, String> responseParams = new HashMap<String, String>();
if (params != null) {
try {
httpPost.setEntity(new StringEntity(params.toString()));
} catch (UnsupportedEncodingException e) {
throw new IDPTokenManagerException("Invalid encoding type.", e);
}
}
HttpPost httpPostWithHeaders = (HttpPost) buildHeaders(httpPost, headers, HTTP_METHODS.POST);
try {
HttpResponse response = httpClient.execute(httpPostWithHeaders);
String status = String.valueOf(response.getStatusLine().getStatusCode());
responseParams.put(Constants.SERVER_RESPONSE_BODY, getResponseBody(response));
responseParams.put(Constants.SERVER_RESPONSE_STATUS, status);
} catch (ClientProtocolException e) {
throw new IDPTokenManagerException("Invalid client protocol.", e);
} catch (IOException e) {
responseParams.put(Constants.SERVER_RESPONSE_BODY, "Internal Server Error");
responseParams.put(Constants.SERVER_RESPONSE_STATUS,
Constants.INTERNAL_SERVER_ERROR);
throw new IDPTokenManagerException("Server connectivity failure.", e);
}
return responseParams;
}
public static Map<String, String> postDataAPI(EndPointInfo apiUtilities,
Map<String, String> headers)
throws IDPTokenManagerException {
HTTP_METHODS httpMethod = apiUtilities.getHttpMethod();
String url = apiUtilities.getEndPoint();
Map<String, String> params = apiUtilities.getRequestParamsMap();
Map<String, String> responseParams = new HashMap<String, String>();
HttpClient httpclient = getCertifiedHttpClient();
String payload = buildPayload(params);
if (httpMethod.equals(HTTP_METHODS.POST)) {
HttpPost httpPost = new HttpPost(url);
HttpPost httpPostWithHeaders = (HttpPost) buildHeaders(httpPost, headers, httpMethod);
byte[] postData = payload.getBytes();
try {
httpPostWithHeaders.setEntity(new ByteArrayEntity(postData));
HttpResponse response = httpclient.execute(httpPostWithHeaders);
String status = String.valueOf(response.getStatusLine().getStatusCode());
responseParams.put(Constants.SERVER_RESPONSE_BODY, getResponseBody(response));
responseParams.put(Constants.SERVER_RESPONSE_STATUS, status);
return responseParams;
} catch (ClientProtocolException e) {
throw new IDPTokenManagerException("Invalid client protocol.", e);
} catch (IOException e) {
responseParams.put(Constants.SERVER_RESPONSE_BODY, "Internal Server Error");
responseParams.put(Constants.SERVER_RESPONSE_STATUS,
Constants.INTERNAL_SERVER_ERROR);
throw new IDPTokenManagerException("Server connectivity failure.", e);
}
}
return responseParams;
}
public static HttpClient getCertifiedHttpClient() throws IDPTokenManagerException {
HttpClient client = null;
InputStream inStream = null;
try {
if (Constants.SERVER_PROTOCOL.equalsIgnoreCase("https://")) {
KeyStore localTrustStore = KeyStore.getInstance("BKS");
inStream =
IdentityProxy.getInstance().getContext().getResources()
.openRawResource(R.raw.emm_truststore);
localTrustStore.load(inStream, Constants.TRUSTSTORE_PASSWORD.toCharArray());
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(),
80));
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(localTrustStore);
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
HttpParams params = new BasicHttpParams();
ClientConnectionManager connectionManager =
new ThreadSafeClientConnManager(params,
schemeRegistry);
client = new DefaultHttpClient(connectionManager, params);
} else {
client = new DefaultHttpClient();
}
} catch (KeyStoreException e) {
throw new IDPTokenManagerException("Invalid keystore.", e);
} catch (CertificateException e) {
throw new IDPTokenManagerException("Invalid certificate.", e);
} catch (NoSuchAlgorithmException e) {
throw new IDPTokenManagerException("Keystore algorithm does not match.");
} catch (UnrecoverableKeyException e) {
throw new IDPTokenManagerException("Invalid keystore.", e);
} catch (KeyManagementException e) {
throw new IDPTokenManagerException("Invalid keystore.", e);
} catch (IOException e) {
throw new IDPTokenManagerException("Trust store failed to load.", e);
} finally {
StreamHandlerUtil.closeInputStream(inStream, TAG);
}
return client;
}
public static String getResponseBody(HttpResponse response) throws IDPTokenManagerException {
String responseBody = null;
HttpEntity entity = null;
try {
entity = response.getEntity();
responseBody = getResponseBodyContent(entity);
} catch (ParseException e) {
throw new IDPTokenManagerException("Invalid response.", e);
} catch (IOException e) {
if (entity != null) {
try {
entity.consumeContent();
} catch (IOException ex) {
throw new IDPTokenManagerException("HTTP Response failure.", e);
}
}
}
return responseBody;
}
public static String getResponseBodyContent(final HttpEntity entity) throws IOException,
ParseException {
InputStream instream = entity.getContent();
if (entity.getContentLength() > Integer.MAX_VALUE) {
throw new IllegalArgumentException("HTTP entity too large to be buffered in memory.");
}
String charset = getContentCharSet(entity);
if (charset == null) {
charset = HTTP.DEFAULT_CONTENT_CHARSET;
}
Reader reader = new InputStreamReader(instream, charset);
StringBuilder buffer = new StringBuilder();
try {
char[] bufferSize = new char[1024];
int length;
while ((length = reader.read(bufferSize)) != -1) {
buffer.append(bufferSize, 0, length);
}
} finally {
reader.close();
}
return buffer.toString();
}
public static String getContentCharSet(final HttpEntity entity) throws ParseException {
String charSet = null;
if (entity.getContentType() != null) {
HeaderElement values[] = entity.getContentType().getElements();
if (values.length > 0) {
NameValuePair param = values[0].getParameterByName("charset");
if (param != null) {
charSet = param.getValue();
}
}
}
return charSet;
}
}

View File

@ -1,75 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.mdm.agent.proxy.utils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class StreamHandlerUtil {
/**
* Close a ByteArrayOutputStream passed in.
*
* @param stream - ByteArrayOutputStream to be closed.
*/
public static void closeOutputStream(OutputStream stream, String tag) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
Log.e(tag, "Exception occured when closing ByteArrayOutputStream." + e);
}
}
}
/**
* Close a InputStream passed in.
*
* @param stream - InputStream to be closed.
*/
public static void closeInputStream(InputStream stream, String tag) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
Log.e(tag, "Exception occured when closing InputStream." + e);
}
}
}
/**
* Close a InputStream passed in.
*
* @param stream - InputStream to be closed.
*/
public static void closeBufferedReader(BufferedReader stream, String tag) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
Log.e(tag, "Exception occured when closing BufferedReader." + e);
}
}
}
}

View File

@ -1,19 +0,0 @@
#
# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. licenses this file to you 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.
#
target=android-21
android.library=true

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<resources>
<string name="app_name">IDPProxy</string>
</resources>

View File

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>

View File

@ -1,20 +0,0 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -1,34 +0,0 @@
#
# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. licenses this file to you 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.
#
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=Google Inc.:Google APIs:${platform}
android.library.reference.1=plugins/ActionBarSherlock/library
android.library.reference.2=plugins/IDPProxy

Some files were not shown because too many files have changed in this diff Show More