Home | History | Annotate | Download | only in embmsmw
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.phone.testapps.embmsmw;
     18 
     19 import android.content.BroadcastReceiver;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.telephony.mbms.FileServiceInfo;
     23 import android.util.Log;
     24 
     25 /**
     26  * Class for triggering artificial events from the frontend app. These would normally not come
     27  * from the frontend app in a real embms implementation.
     28  */
     29 public class SideChannelReceiver extends BroadcastReceiver {
     30     public static final String ACTION_TRIGGER_CLEANUP =
     31             "com.android.phone.testapps.embmsmw.TRIGGER_CLEANUP";
     32     public static final String ACTION_REQUEST_SPURIOUS_TEMP_FILES =
     33             "com.android.phone.testapps.embmsmw.REQUEST_SPURIOUS_TEMP_FILES";
     34     public static final String ACTION_DELAY_DOWNLOAD =
     35             "com.android.phone.testapps.embmsmw.DELAY_DOWNLOAD";
     36 
     37     public static final String EXTRA_SERVICE_INFO =
     38             "com.android.phone.testapps.embmsmw.SERVICE_INFO";
     39     public static final String EXTRA_DELAY_FACTOR =
     40             "com.android.phone.testapps.embmsmw.DELAY_FACTOR";
     41 
     42     private static final String LOG_TAG = "EmbmsSampleMwSC";
     43     @Override
     44     public void onReceive(Context context, Intent intent) {
     45         EmbmsSampleDownloadService downloadService = EmbmsSampleDownloadService.getInstance();
     46         if (downloadService == null) {
     47             Log.w(LOG_TAG, "don't have instance of dl service");
     48             return;
     49         }
     50         switch (intent.getAction()) {
     51             case ACTION_TRIGGER_CLEANUP:
     52                 downloadService.requestCleanup();
     53                 break;
     54             case ACTION_REQUEST_SPURIOUS_TEMP_FILES:
     55                 FileServiceInfo serviceInfo = intent.getParcelableExtra(EXTRA_SERVICE_INFO);
     56                 downloadService.requestExtraTempFiles(serviceInfo);
     57                 break;
     58             case ACTION_DELAY_DOWNLOAD:
     59                 // Increase download latency by a certain factor
     60                 downloadService.delayDownloads(intent.getIntExtra(EXTRA_DELAY_FACTOR, 1));
     61                 break;
     62         }
     63     }
     64 }
     65