forked from AOSPA/android_packages_apps_ParanoidHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateStateService.java
104 lines (91 loc) · 3.79 KB
/
UpdateStateService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (C) 2022 Paranoid Android
*
* 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 co.aospa.hub;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.Nullable;
import co.aospa.hub.components.ComponentBuilder;
import co.aospa.hub.controllers.NotificationController;
import co.aospa.hub.controllers.UpdateStateController;
import co.aospa.hub.util.Constants;
public class UpdateStateService extends Service {
private static final String TAG = "UpdateStateService";
private final IBinder mBinder = new LocalBinder();
private UpdateStateController mStateController;
@Override
public void onCreate() {
super.onCreate();
mStateController = UpdateStateController.get(this);
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "Start service for intent " + intent);
boolean shouldStartSticky = false;
if (Constants.INTENT_ACTION_CHECK_UPDATES.equals(intent.getAction())) {
getComponent(ComponentBuilder.COMPONENT_UPDATES, true);
} else if (Constants.INTENT_ACTION_UPDATE_CHANGELOG.equals(intent.getAction())) {
getComponent(ComponentBuilder.COMPONENT_CHANGELOG, false);
} else {
getComponent(ComponentBuilder.COMPONENT_CONFIG, false);
}
if (Constants.INTENT_ACTION_UPDATE.equals(intent.getAction())) {
UpdateStateController controller = getController();
shouldStartSticky = true;
String action = intent.getStringExtra(Constants.EXTRA_DOWNLOAD);
switch (action) {
case Constants.EXTRA_DOWNLOAD_ACTION_PAUSE:
controller.cancelOrPauseDownloadTask(false);
break;
case Constants.EXTRA_DOWNLOAD_ACTION_RESUME:
controller.resumeDownloadTask();
break;
case Constants.EXTRA_DOWNLOAD_ACTION_CANCEL:
controller.cancelOrPauseDownloadTask(true);
break;
default:
NotificationController notificationController = new NotificationController(this);
if (notificationController != null) {
notificationController.cancelNotification();
}
controller.startDownloadTask();
}
} else if (Constants.INTENT_ACTION_UPDATE_INSTALL_LEGACY.equals(intent.getAction())) {
UpdateStateController controller = getController();
controller.startLegacyInstallTaskIfPossible();
}
return shouldStartSticky ? START_STICKY : START_NOT_STICKY;
}
private void getComponent(String component, boolean userRequested) {
UpdateStateController controller = getController();
controller.getComponentFromServer(component, userRequested);
}
public class LocalBinder extends Binder {
public UpdateStateService getService() {
return UpdateStateService.this;
}
}
public UpdateStateController getController() {
return mStateController;
}
}