Clean up sendMessage calls
[fonbot.git] / src / ro / ieval / fonbot / FonBotAdminReceiver.java
CommitLineData
8dfb76c9
MG
1package ro.ieval.fonbot;
2
3import static ro.ieval.fonbot.R.string.*;
4
5import static ro.ieval.fonbot.Utils.toNonNull;
6
7import org.eclipse.jdt.annotation.Nullable;
8
9import ro.ieval.fonbot.Utils.MessageType;
10import android.app.admin.DeviceAdminReceiver;
11import android.app.admin.DevicePolicyManager;
12import android.content.Context;
13import android.content.Intent;
14import android.util.Log;
15
16/*
17 * Copyright © 2013 Marius Gavrilescu
18 *
19 * This file is part of FonBot.
20 *
21 * FonBot is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
25 *
26 * FonBot is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU General Public License
32 * along with FonBot. If not, see <http://www.gnu.org/licenses/>.
33 */
34
35/**
36 * The {@link DeviceAdminReceiver} used by FonBot. Sends {@link Utils.MessageType#ADMIN ADMIN} and {@link Utils.MessageType#WATCH_LOGIN WATCH_LOGIN} notifications.
37 *
38 * @author Marius Gavrilescu <marius@ieval.ro>
39 */
40public final class FonBotAdminReceiver extends DeviceAdminReceiver {
41 @Override
42 public void onDisabled(@Nullable final Context context, @Nullable final Intent intent) {
43 if(context==null)
44 return;
e4e4926f 45 Utils.sendMessage(context, toNonNull(MessageType.ADMIN), admin_disabled);
8dfb76c9
MG
46 }
47
48 @Override
49 public @Nullable CharSequence onDisableRequested(@Nullable final Context context, @Nullable final Intent intent) {
50 if(context==null){
51 Log.wtf(getClass().getName(), "context is null in onDisableRequested");
52 throw new AssertionError("Log.wtf did not terminate the process");
53 }
e4e4926f 54 Utils.sendMessage(context, toNonNull(MessageType.ADMIN), admin_disable_requested);
8dfb76c9
MG
55 return null;//TODO: write this
56 }
57
58 @Override
59 public void onEnabled(@Nullable final Context context, @Nullable final Intent intent) {
60 if(context==null)
61 return;
e4e4926f 62 Utils.sendMessage(context, toNonNull(MessageType.ADMIN), admin_enabled);
8dfb76c9
MG
63 }
64
65 @Override
66 public void onPasswordChanged(@Nullable final Context context, @Nullable final Intent intent) {
67 if(context==null)
68 return;
e4e4926f 69 Utils.sendMessage(context, toNonNull(MessageType.ADMIN), device_password_changed);
8dfb76c9
MG
70 }
71
72 @SuppressWarnings("boxing")
73 @Override
74 public void onPasswordFailed(@Nullable final Context context, @Nullable final Intent intent) {
75 if(context==null)
76 return;
8bfdcf7a 77 final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
e4e4926f 78 Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN), device_login_failed_fmt, dpm.getCurrentFailedPasswordAttempts());
8dfb76c9
MG
79 }
80
81 @Override
82 public void onPasswordSucceeded(@Nullable final Context context, @Nullable final Intent intent) {
83 if(context==null)
84 return;
e4e4926f 85 Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN), device_login_succeeded);
8dfb76c9
MG
86 }
87}
This page took 0.017478 seconds and 4 git commands to generate.