blob: 996c87430553e8d7d6731f75d02ab3531beda9af [file] [log] [blame]
/*
* Copyright 2016 Fairphone B.V.
*
* Licensed 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 com.fairphone.hiccup.app;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class HiccupReceiver extends BroadcastReceiver {
public HiccupReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
if(!HiccupUtil.isOwner(context)) {
return;
}
if (intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) {
Intent pushIntent = new Intent(context, HiccupService.class);
pushIntent.setAction(HiccupService.ACTION_CHECK_UPLOAD);
context.startService(pushIntent);
}
if (intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) {
Intent activityIntent = new Intent(context,HiccupSettings.class);
activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activityIntent);
}
/* Everything below here we only want to do if Hiccupd is running */
if (!HiccupUtil.isHiccupdRunning()) {
HiccupUtil.LOG("Hiccup is not running.");
return;
}
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent pushIntent = new Intent(context, HiccupService.class);
pushIntent.setAction(HiccupService.ACTION_REBOOT_COMPLETE);
context.startService(pushIntent);
}
if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
Intent pushIntent = new Intent(context, HiccupService.class);
pushIntent.setAction(HiccupService.ACTION_SHUTDOWN);
context.startService(pushIntent);
}
}
}