]>
Commit | Line | Data |
---|---|---|
1 | package ro.ieval.fonbot; | |
2 | ||
3 | import static ro.ieval.fonbot.R.string.*; | |
4 | ||
5 | import static ro.ieval.fonbot.Utils.toNonNull; | |
6 | ||
7 | import org.eclipse.jdt.annotation.Nullable; | |
8 | ||
9 | import ro.ieval.fonbot.Utils.MessageType; | |
10 | import android.app.admin.DeviceAdminReceiver; | |
11 | import android.app.admin.DevicePolicyManager; | |
12 | import android.content.Context; | |
13 | import android.content.Intent; | |
14 | import 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 | */ | |
40 | public 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; | |
45 | Utils.sendMessage(context, toNonNull(MessageType.ADMIN), admin_disabled); | |
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 | } | |
54 | Utils.sendMessage(context, toNonNull(MessageType.ADMIN), admin_disable_requested); | |
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; | |
62 | Utils.sendMessage(context, toNonNull(MessageType.ADMIN), admin_enabled); | |
63 | } | |
64 | ||
65 | @Override | |
66 | public void onPasswordChanged(@Nullable final Context context, @Nullable final Intent intent) { | |
67 | if(context==null) | |
68 | return; | |
69 | Utils.sendMessage(context, toNonNull(MessageType.ADMIN), device_password_changed); | |
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; | |
77 | final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); | |
78 | Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN), device_login_failed_fmt, dpm.getCurrentFailedPasswordAttempts()); | |
79 | } | |
80 | ||
81 | @Override | |
82 | public void onPasswordSucceeded(@Nullable final Context context, @Nullable final Intent intent) { | |
83 | if(context==null) | |
84 | return; | |
85 | Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN), device_login_succeeded); | |
86 | } | |
87 | } |