Home | History | Annotate | Download | only in gceservice
      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 package com.android.google.gce.gceservice;
     17 
     18 import android.bluetooth.BluetoothAdapter;
     19 import android.content.BroadcastReceiver;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.net.ConnectivityManager;
     23 import android.net.NetworkInfo;
     24 import android.util.Log;
     25 
     26 import com.android.google.gce.gceservice.GceService;
     27 
     28 public class GceBroadcastReceiver extends BroadcastReceiver {
     29     private static final String LOG_TAG = "GceBroadcastReceiver";
     30 
     31 
     32     private void reportIntent(Context context, String intentType) {
     33         Intent intent = new Intent(context, GceService.class);
     34         intent.setAction(intentType);
     35         context.startService(intent);
     36     }
     37 
     38 
     39     @Override
     40     public void onReceive(Context context, Intent intent) {
     41         if (intent != null) {
     42             final String action = intent.getAction();
     43             Log.i(LOG_TAG, "Received broadcast: " + action);
     44 
     45             if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
     46                 reportIntent(context, GceService.INTENT_ACTION_CONFIGURE);
     47             } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
     48                 reportIntent(context, GceService.INTENT_ACTION_NETWORK_CHANGED);
     49             } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
     50                 reportIntent(context, GceService.INTENT_ACTION_BLUETOOTH_CHANGED);
     51             }
     52         }
     53     }
     54 }
     55