Skip to content

Commit

Permalink
Merge pull request #133 from charithag/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamidu Sachith Punchihewa committed Jan 4, 2018
2 parents c77d7dc + 6db8c41 commit 6d52583
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 105 deletions.
4 changes: 2 additions & 2 deletions client/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ android {
targetSdkVersion 25
multiDexEnabled true

versionCode 3010025
versionName "3.1.25"
versionCode 3010026
versionName "3.1.26"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
27 changes: 13 additions & 14 deletions client/client/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@
android:name=".services.NetworkInfoService"
android:enabled="true" />
<service android:name=".services.kiosk.KioskLockDownService" />

<service android:name=".services.kiosk.KioskUnlockService" />
<service android:name=".services.kiosk.KioskMsgAlarmService"
android:enabled="true"/>
<service
android:name=".services.kiosk.KioskMsgAlarmService"
android:enabled="true" />

<activity android:name=".activities.AlreadyRegisteredActivity" />
<activity
Expand All @@ -212,9 +212,9 @@
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Holo.Dialog.NoActionBar" />
<activity
android:name=".activities.ScreenShareActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Holo.Dialog.NoActionBar" />
android:name=".activities.ScreenShareActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Holo.Dialog.NoActionBar" />
<activity
android:name=".LockActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
Expand All @@ -238,17 +238,16 @@
android:name=".services.AppLockService"
android:exported="false"
android:permission="org.wso2.iot.agent.permission.ACCESS" />
<service android:name=".InstanceIDListenerService">
<service
android:name=".services.screenshare.ScreenSharingService"
android:exported="false"></service>
<service
android:name=".services.FCMInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>

<service
android:name=".services.screenshare.ScreenSharingService"
android:exported="false">
</service>

<activity
android:name=".KioskActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
Expand Down Expand Up @@ -276,9 +275,9 @@
<action android:name="org.ws2.iot.agent.LOCATION_UPDATE" />
</intent-filter>
</receiver>
<receiver android:name=".services.kiosk.KioskAlarmReceiver"></receiver>
<receiver android:name=".services.kiosk.KioskAlarmReceiver" />

<!--android 7 requirement-->
<!-- android 7 requirement -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ public void onClick(View v) {
missingPermissions.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

if (!missingPermissions.isEmpty()) {
if (missingPermissions.isEmpty()) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(Constants.PERMISSION_MISSING, Constants.PERMISSION_MISSING_NOTIFICATION_ID);
} else {
ActivityCompat.requestPermissions(AlreadyRegisteredActivity.this,
missingPermissions.toArray(new String[missingPermissions.size()]),
110);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import android.widget.TextView;
import android.widget.Toast;

import com.google.firebase.iid.FirebaseInstanceId;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -889,10 +891,19 @@ private void manipulateConfigurationResponse(Map<String, String> result) {
if(param.getString(context.getString(R.string.shared_pref_config_key)).trim().equals(
Constants.PreferenceFlag.NOTIFIER_TYPE)){
String type = param.getString(context.getString(R.string.shared_pref_config_value)).trim();
if(type.equals(String.valueOf(Constants.NOTIFIER_CHECK))) {
if (type.equals(String.valueOf(Constants.NOTIFIER_CHECK))) {
Preference.putString(context, Constants.PreferenceFlag.NOTIFIER_TYPE,
Constants.NOTIFIER_FCM);
}else{
String token = FirebaseInstanceId.getInstance().getToken();
if(token != null) {
if (Constants.DEBUG_MODE_ENABLED){
Log.d(TAG, "FCM Token: " + token);
}
} else {
Log.i(TAG, "FCM Token is still null. " +
"Will retry again when registering the agent.");
}
} else {
Preference.putString(context, Constants.PreferenceFlag.NOTIFIER_TYPE,
Constants.NOTIFIER_LOCAL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;

import com.google.firebase.iid.FirebaseInstanceId;

Expand All @@ -47,33 +52,48 @@
* Activity which handles user enrollment.
*/
public class RegistrationActivity extends Activity implements APIResultCallBack {

private static final String TAG = RegistrationActivity.class.getSimpleName();
private static final int FCM_TOKEN_WAIT_MILLIS = 60000;

private Context context;
private ProgressDialog progressDialog;
private DeviceInfoPayload deviceInfoBuilder;
private String TAG = RegistrationActivity.class.getSimpleName();
private boolean isFCMTokenReceiverRegistered = false;

private BroadcastReceiver fcmTokenReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
CommonDialogUtils.stopProgressDialog(progressDialog);
registerDevice();
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
context = this;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}

@Override
protected void onResume(){
super.onResume();
if (Constants.NOTIFIER_FCM.equals(Preference.getString(context, Constants.PreferenceFlag.NOTIFIER_TYPE))) {
registerFCM();
} else {
registerDevice();
}
deviceInfoBuilder = new DeviceInfoPayload(context);
DeviceInfo deviceInfo = new DeviceInfo(context);
String deviceIdentifier = deviceInfo.getDeviceId();
Preference.putString(context, Constants.PreferenceFlag.REG_ID, deviceIdentifier);
registerDevice();

}

@Override
protected void onDestroy(){
super.onDestroy();
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
protected void onPause(){
super.onPause();
CommonDialogUtils.stopProgressDialog(progressDialog);
if (isFCMTokenReceiverRegistered) {
unregisterReceiver(fcmTokenReceiver);
}
}

Expand All @@ -82,6 +102,12 @@ private void registerDevice() {
getResources().getString(R.string.dialog_enrolling),
getResources().getString(R.string.dialog_please_wait),
null);

DeviceInfoPayload deviceInfoBuilder = new DeviceInfoPayload(context);
DeviceInfo deviceInfo = new DeviceInfo(context);
String deviceIdentifier = deviceInfo.getDeviceId();
Preference.putString(context, Constants.PreferenceFlag.REG_ID, deviceIdentifier);

String type = Preference.getString(context,
context.getResources().getString(R.string.shared_pref_reg_type));
String username = Preference.getString(context,
Expand Down Expand Up @@ -270,45 +296,29 @@ public void onReceiveAPIResult(Map<String, String> result, int requestCode) {
private void registerFCM() {
String token = FirebaseInstanceId.getInstance().getToken();
if(token != null) {
Preference.putString(context, Constants.FCM_REG_ID, token);
} else {
try {
CommonUtils.clearAppData(context);
displayFCMServicesError();
} catch (AndroidAgentException e) {
Log.e(TAG, "Failed to clear app data", e);
if (Constants.DEBUG_MODE_ENABLED){
Log.d(TAG, "FCM Token: " + token);
}
}
}

/**
* This is used to send the registration Id to MDM server so that the server
* can use it as a reference to identify the device when sending messages to
* Google server.
*
* @throws AndroidAgentException
*/
public void sendRegistrationId() throws AndroidAgentException {
DeviceInfo deviceInfo = new DeviceInfo(context);
DeviceInfoPayload deviceInfoPayload = new DeviceInfoPayload(context);
deviceInfoPayload.build();

String replyPayload = deviceInfoPayload.getDeviceInfoPayload();
String ipSaved = Constants.DEFAULT_HOST;
String prefIP = Preference.getString(context, Constants.PreferenceFlag.IP);
if (prefIP != null) {
ipSaved = prefIP;
}
if (ipSaved != null && !ipSaved.isEmpty()) {
ServerConfig utils = new ServerConfig();
utils.setServerIP(ipSaved);

String url = utils.getAPIServerURL(context) + Constants.DEVICE_ENDPOINT + deviceInfo.getDeviceId();

CommonUtils.callSecuredAPI(context, url, org.wso2.iot.agent.proxy.utils.Constants.HTTP_METHODS.PUT,
replyPayload, RegistrationActivity.this, Constants.FCM_REGISTRATION_ID_SEND_CODE);
Preference.putString(context, Constants.FCM_REG_ID, token);
registerDevice();
} else {
Log.e(TAG, "There is no valid IP to contact the server");
Log.w(TAG, "FCM Token is null. Will depend on FCMInstanceIdService.");
Preference.removePreference(context, Constants.FCM_REG_ID);
progressDialog = CommonDialogUtils.showProgressDialog(RegistrationActivity.this,
getResources().getString(R.string.dialog_enrolling),
getResources().getString(R.string.dialog_configuring_fcm),
null);
isFCMTokenReceiverRegistered = true;
registerReceiver(fcmTokenReceiver,
new IntentFilter(Constants.FCM_TOKEN_REFRESHED_BROADCAST_ACTION));
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
unregisterReceiver(fcmTokenReceiver);
isFCMTokenReceiverRegistered = false;
displayFCMServicesError();
}
}, FCM_TOKEN_WAIT_MILLIS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void run() {
}
}, AUTO_HIDE_DELAY_MILLIS);
}

}

private void startActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void onClick(View view) {
private void startManagedProfileManager() {
Intent ManagedProfileManager = new Intent(getApplicationContext(), WorkProfileManager.class);
startActivity(ManagedProfileManager);
finish();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public void onReceiveAPIResult(Map<String, String> arg0, int arg1) {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onProfileProvisioningComplete(Context context, Intent intent) {
Log.i(TAG, "Profile provisioning completed");
if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP)) {
DevicePolicyManager devicePolicyManager =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
Expand Down Expand Up @@ -212,7 +213,7 @@ public void onProfileProvisioningComplete(Context context, Intent intent) {
Preference.putBoolean(context,Constants.PreferenceFlag.DEVICE_INITIALIZED, false);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(launch);
} else {
} else if (!Preference.hasPreferenceKey(context, Constants.PreferenceFlag.REGISTERED)){
Intent launch = new Intent(context, EnableProfileActivity.class);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(launch);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2018, 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.iot.agent.services;

import android.content.Intent;
import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

import org.wso2.iot.agent.utils.Constants;
import org.wso2.iot.agent.utils.Preference;

public class FCMInstanceIdService extends FirebaseInstanceIdService {

private static final String TAG = FCMInstanceIdService.class.getSimpleName();

@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String token = FirebaseInstanceId.getInstance().getToken();
if (Constants.DEBUG_MODE_ENABLED){
Log.d(TAG, "FCM Token: " + token);
}
Preference.putString(this, Constants.FCM_REG_ID, token);
Intent intent = new Intent();
intent.setAction(Constants.FCM_TOKEN_REFRESHED_BROADCAST_ACTION);
sendBroadcast(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class Constants {
public static final String LOCATION_UPDATE_BROADCAST_ACTION = "org.ws2.iot.agent.LOCATION_UPDATE";
public static final String SYNC_BROADCAST_ACTION = "org.ws2.iot.agent.SERVER_SYNC";
public static final String AGENT_UPDATED_BROADCAST_ACTION = "org.ws2.iot.agent.APPLICATION_UPDATED";
public static final String FCM_TOKEN_REFRESHED_BROADCAST_ACTION = "org.ws2.iot.agent.FCM_TOKEN_REFRESHED";
public static final String HTTPS_PROTOCOL = "https://";
public static final String OWNERSHIP_BYOD = "BYOD";
public static final String OWNERSHIP_COPE = "COPE";
Expand Down

0 comments on commit 6d52583

Please sign in to comment.