Differential D16491 Diff 53464 src/org/kde/kdeconnect/Plugins/SharePlugin/ShareBroadcastReceiver.java
Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/SharePlugin/ShareBroadcastReceiver.java
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Erik Duisters <e.duisters1@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | package org.kde.kdeconnect.Plugins.SharePlugin; | ||||
22 | | ||||
23 | import android.content.BroadcastReceiver; | ||||
24 | import android.content.Context; | ||||
25 | import android.content.Intent; | ||||
26 | import android.util.Log; | ||||
27 | | ||||
28 | import org.kde.kdeconnect.BackgroundService; | ||||
29 | | ||||
30 | public class ShareBroadcastReceiver extends BroadcastReceiver { | ||||
31 | @Override | ||||
32 | public void onReceive(Context context, Intent intent) { | ||||
33 | switch (intent.getAction()) { | ||||
34 | case SharePlugin.ACTION_CANCEL_SHARE: | ||||
35 | cancelShare(context, intent); | ||||
36 | break; | ||||
37 | default: | ||||
38 | Log.d("ShareBroadcastReceiver", "Unhandled Action received: " + intent.getAction()); | ||||
39 | } | ||||
40 | } | ||||
41 | | ||||
42 | private void cancelShare(Context context, Intent intent) { | ||||
43 | if (!intent.hasExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA) || | ||||
44 | !intent.hasExtra(SharePlugin.CANCEL_SHARE_DEVICE_ID_EXTRA)) { | ||||
45 | Log.e("ShareBroadcastReceiver", "cancelShare() - not all expected extra's are present. Ignoring this cancel intent"); | ||||
46 | return; | ||||
47 | } | ||||
48 | | ||||
49 | long jobId = intent.getLongExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA, -1); | ||||
50 | String deviceId = intent.getStringExtra(SharePlugin.CANCEL_SHARE_DEVICE_ID_EXTRA); | ||||
51 | | ||||
52 | BackgroundService.RunCommand(context, service -> { | ||||
53 | SharePlugin plugin = service.getDevice(deviceId).getPlugin(SharePlugin.class); | ||||
54 | plugin.cancelJob(jobId); | ||||
55 | }); | ||||
56 | } | ||||
57 | } |