]>
Commit | Line | Data |
---|---|---|
8dfb76c9 MG |
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), | |
55 | toNonNull(context.getString(admin_disable_requested))); | |
56 | return null;//TODO: write this | |
57 | } | |
58 | ||
59 | @Override | |
60 | public void onEnabled(@Nullable final Context context, @Nullable final Intent intent) { | |
61 | if(context==null) | |
62 | return; | |
63 | Utils.sendMessage(context, toNonNull(MessageType.ADMIN), | |
64 | toNonNull(context.getString(admin_enabled))); | |
65 | } | |
66 | ||
67 | @Override | |
68 | public void onPasswordChanged(@Nullable final Context context, @Nullable final Intent intent) { | |
69 | if(context==null) | |
70 | return; | |
71 | Utils.sendMessage(context, toNonNull(MessageType.ADMIN), | |
72 | toNonNull(context.getString(device_password_changed))); | |
73 | } | |
74 | ||
75 | @SuppressWarnings("boxing") | |
76 | @Override | |
77 | public void onPasswordFailed(@Nullable final Context context, @Nullable final Intent intent) { | |
78 | if(context==null) | |
79 | return; | |
8bfdcf7a | 80 | final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); |
8dfb76c9 MG |
81 | Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN), |
82 | toNonNull(context.getString(device_login_failed_fmt, dpm.getCurrentFailedPasswordAttempts()))); | |
83 | } | |
84 | ||
85 | @Override | |
86 | public void onPasswordSucceeded(@Nullable final Context context, @Nullable final Intent intent) { | |
87 | if(context==null) | |
88 | return; | |
89 | Utils.sendMessage(context, toNonNull(MessageType.WATCH_LOGIN), toNonNull(context.getString(device_login_succeeded))); | |
90 | } | |
91 | } |