Wednesday 2 December 2020

Android studio updated and code too large now

I have a system that has been production for 2 years now. It is an EMM system for controlling corporate devices.

It uses FireBase to send the functionality executed on the device from the server app to the device.

There are around 400 possible commands you can send to a device and all these commands are handled in one class initially, which overrides the onMessageReceived() from the FireBaseMessagingService class.

The older version of Android studio built the apk which is now in production. I have started to work on version 2 of my system after about a year off. so i updated my Android studio to the latest (4).

The Problem:

when i try build the project and push onto a device, i get

error: code too large public void onMessageReceived(RemoteMessage remoteMessage) {

As stated before this onMessageReceived method can handle 400 different types of push notification from the server app, so there are a lot of if/else statements in the method body.

Is there any reason why since the AS upgrade this will not work.

is there any setting i can change in AS to get past this?

What I have tried:

I thought about putting half of the if/elses in another service class, to cut down on the method code. This would involve passing the remoteMessageMap to another class to carry on with the if/else processing.

remoteMessageMap from FireBase is a Map and Maps are not serializable as they extend interface, so can't pass it.

public class MyAndroidFirebaseMsgService extends FirebaseMessagingService {

    private static final String TAG = "MyAndroidFCMService";
    AppObj appObj;


    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {


        Log.e(TAG, "remoteMessage.getData() = " + remoteMessage.getData());

        Map remoteMessageMap = remoteMessage.getData();

        String message = (String)remoteMessageMap.get("message");

thanks

[edit1]

else if(message.trim().equalsIgnoreCase("CLEARCACHE_REMOVE_APP_WL")){


            Log.e(TAG, "received CLEARCACHE_REMOVE_APP_WL");

            String pushGuid =  (String)remoteMessageMap.get("pushguid");
            Log.e(TAG, "pushGuid = " + pushGuid);

            String clearCacheRemoveWhitelist =  (String)remoteMessageMap.get("clear_cache_app_names");


            Intent intentExecutePushCommand = new Intent( getApplicationContext(), ExecutePushCommandIntentService.class);
            intentExecutePushCommand.putExtra("compID", MenuActivity.companyID);
            intentExecutePushCommand.putExtra("command", message);
            intentExecutePushCommand.putExtra("pushguid", pushGuid);
            intentExecutePushCommand.putExtra("clear_cache_app_names", clearCacheRemoveWhitelist);



            startService(intentExecutePushCommand);

        }else if(message.trim().equalsIgnoreCase("CLEARCACHE_GET_PACKAGENAMES_WL")){


            Log.e(TAG, "received CLEARCACHE_GET_PACKAGENAMES_WL");

            String pushGuid =  (String)remoteMessageMap.get("pushguid");
            Log.e(TAG, "pushGuid = " + pushGuid);


            Intent intentExecutePushCommand = new Intent( getApplicationContext(), ExecutePushCommandIntentService.class);
            intentExecutePushCommand.putExtra("compID", MenuActivity.companyID);
            intentExecutePushCommand.putExtra("command", message);
            intentExecutePushCommand.putExtra("pushguid", pushGuid);

            startService(intentExecutePushCommand);

        }else if(message.trim().equalsIgnoreCase("CLEARCACHE_ADD_PACKAGENAME_WL")){


            Log.e(TAG, "received CLEARCACHE_ADD_PACKAGENAME_WL");

            String pushGuid =  (String)remoteMessageMap.get("pushguid");
            Log.e(TAG, "pushGuid = " + pushGuid);

            String packageName =  (String)remoteMessageMap.get("package_name");


            Intent intentExecutePushCommand = new Intent( getApplicationContext(), ExecutePushCommandIntentService.class);
            intentExecutePushCommand.putExtra("compID", MenuActivity.companyID);
            intentExecutePushCommand.putExtra("command", message);
            intentExecutePushCommand.putExtra("pushguid", pushGuid);
            intentExecutePushCommand.putExtra("package_name", packageName);

            startService(intentExecutePushCommand);

        }


from Android studio updated and code too large now

No comments:

Post a Comment