Skip to content
This repository was archived by the owner on Nov 25, 2017. It is now read-only.

Commit 73a3446

Browse files
committed
update lib: (DaemonService)
1 parent 50b2520 commit 73a3446

File tree

7 files changed

+87
-18
lines changed

7 files changed

+87
-18
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
.idea/vcs.xml
1212
app/libs/
1313
app/src/main/res/values-v21/
14+
.idea/
15+
.idea/inspectionProfiles/

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

X.patch

+56-9
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,57 @@ Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
7878
import com.lody.virtual.helper.component.BaseService;
7979

8080
/**
81-
@@ -29,8 +32,10 @@
81+
@@ -14,7 +17,7 @@
82+
*/
83+
public class DaemonService extends BaseService {
84+
85+
- private static final int NOTIFY_ID = 1001;
86+
+ private static final int NOTIFY_ID = 1001;
87+
88+
public static void startup(Context context) {
89+
context.startService(new Intent(context, DaemonService.class));
90+
@@ -29,9 +32,15 @@
8291
@Override
8392
public void onCreate() {
8493
super.onCreate();
85-
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
94+
+ ForegroundNotificationDelegate foregroundNotificationDelegate = VirtualCore.get().foregroundNotificationDelegate;
95+
+ if (foregroundNotificationDelegate == null) {
8696
- startService(new Intent(this, InnerService.class));
87-
+ startService(new Intent(this, InnerService.class));
8897
- startForeground(NOTIFY_ID, new Notification());
89-
+ ForegroundNotificationDelegate foregroundNotificationDelegate = VirtualCore.get().foregroundNotificationDelegate;
90-
+ startForeground(NOTIFY_ID, foregroundNotificationDelegate == null ? new Notification() : foregroundNotificationDelegate.getNotification());
91-
98+
+ startService(new Intent(this, InnerService.class));
99+
+ startForeground(NOTIFY_ID, new Notification());
100+
-
101+
+ } else if (foregroundNotificationDelegate.isEnable()) {
102+
+ startForeground(NOTIFY_ID, foregroundNotificationDelegate.getNotification());
103+
+ if (foregroundNotificationDelegate.isTryToHide())
104+
+ startService(new Intent(this, InnerService.class));
105+
+ }
92106
}
93107

108+
@Override
109+
@@ -41,14 +50,14 @@
110+
111+
public static final class InnerService extends BaseService {
112+
113+
- @Override
114+
- public int onStartCommand(Intent intent, int flags, int startId) {
115+
- startForeground(NOTIFY_ID, new Notification());
116+
- stopForeground(true);
117+
- stopSelf();
118+
- return super.onStartCommand(intent, flags, startId);
119+
- }
120+
- }
121+
+ @Override
122+
+ public int onStartCommand(Intent intent, int flags, int startId) {
123+
+ startForeground(NOTIFY_ID, new Notification());
124+
+ stopForeground(true);
125+
+ stopSelf();
126+
+ return super.onStartCommand(intent, flags, startId);
127+
+ }
128+
+ }
129+
130+
131+
}
94132
Index: lib/src/main/java/com/lody/virtual/client/VClientImpl.java
95133
IDEA additional info:
96134
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
@@ -126,7 +164,7 @@ Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
126164
===================================================================
127165
--- lib/src/main/java/com/lody/virtual/client/hook/patchs/notification/compat/RemoteViewsUtils.java (revision 30d07f02ec29ccecfacbd2c627394a71565fb665)
128166
+++ lib/src/main/java/com/lody/virtual/client/hook/patchs/notification/compat/RemoteViewsUtils.java (revision )
129-
@@ -115,14 +115,9 @@
167+
@@ -115,16 +115,11 @@
130168
}
131169
int mode;
132170
// TODO 各种适配
@@ -141,25 +179,34 @@ Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
141179
- mCache.layout(0, 0, width, height);
142180
+ mCache.layout(0, 0, mCache.getMeasuredWidth(), mCache.getMeasuredHeight());
143181
VLog.i(TAG, "notification:systemId=" + systemId + ",max=%d/%d, szie=%d/%d", width, height,
144-
mCache.getMeasuredWidth(), mCache.getMeasuredHeight());
182+
- mCache.getMeasuredWidth(), mCache.getMeasuredHeight());
183+
+ width, mCache.getMeasuredHeight());
145184
// 打印action
185+
// logActions(remoteViews, view1);
186+
return mCache;
146187
Index: lib/src/main/java/com/lody/virtual/client/hook/delegate/ForegroundNotificationDelegate.java
147188
IDEA additional info:
148189
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
149190
<+>UTF-8
150191
===================================================================
151192
--- lib/src/main/java/com/lody/virtual/client/hook/delegate/ForegroundNotificationDelegate.java (revision )
152193
+++ lib/src/main/java/com/lody/virtual/client/hook/delegate/ForegroundNotificationDelegate.java (revision )
153-
@@ -0,0 +1,9 @@
194+
@@ -0,0 +1,14 @@
154195
+package com.lody.virtual.client.hook.delegate;
155196
+
156197
+import android.app.Notification;
157198
+
158199
+public interface ForegroundNotificationDelegate {
200+
+
159201
+ Notification getNotification();
160202
+
203+
+ boolean isEnable();
204+
+
205+
+ boolean isTryToHide();
206+
+
161207
+ String getGroup(String orig);
162208
+}
209+
\ No newline at end of file
163210
Index: lib/src/main/java/com/lody/virtual/client/core/VirtualCore.java
164211
IDEA additional info:
165212
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP

app/src/main/java/one/codehz/container/delegate/MyForegroundNotificationDelegate.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package one.codehz.container.delegate
22

3-
import android.annotation.TargetApi
43
import android.app.Notification
54
import android.content.Context
6-
import android.os.Build
75
import com.lody.virtual.client.hook.delegate.ForegroundNotificationDelegate
86
import one.codehz.container.R
97

10-
@TargetApi(Build.VERSION_CODES.N)
8+
119
class MyForegroundNotificationDelegate(val context: Context) : ForegroundNotificationDelegate {
10+
override fun isEnable() = true
11+
12+
override fun isTryToHide() = false
13+
1214
override fun getNotification()
1315
= Notification.Builder(context)
1416
.setContentTitle(context.getString(R.string.foreground_notification_title))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.lody.virtual.client.hook.delegate;
2+
3+
import android.app.Notification;
4+
5+
public interface ForegroundNotificationDelegate {
6+
7+
Notification getNotification();
8+
9+
boolean isEnable();
10+
11+
boolean isTryToHide();
12+
13+
String getGroup(String orig);
14+
}

lib/src/main/java/com/lody/virtual/client/hook/patchs/notification/compat/RemoteViewsUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public View createView(final Context context, RemoteViews remoteViews, boolean i
117117
// TODO 各种适配
118118
mode = View.MeasureSpec.AT_MOST;
119119
mCache.measure(View.MeasureSpec.makeMeasureSpec(width, mode), View.MeasureSpec.makeMeasureSpec(height, mode));
120-
mCache.layout(0, 0, mCache.getMeasuredWidth(), mCache.getMeasuredHeight());
120+
mCache.layout(0, 0, width, mCache.getMeasuredHeight());
121121
VLog.i(TAG, "notification:systemId=" + systemId + ",max=%d/%d, szie=%d/%d", width, height,
122122
mCache.getMeasuredWidth(), mCache.getMeasuredHeight());
123123
// 打印action

lib/src/main/java/com/lody/virtual/client/stub/DaemonService.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ public void onDestroy() {
3232
@Override
3333
public void onCreate() {
3434
super.onCreate();
35-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
36-
startService(new Intent(this, InnerService.class));
3735
ForegroundNotificationDelegate foregroundNotificationDelegate = VirtualCore.get().foregroundNotificationDelegate;
38-
startForeground(NOTIFY_ID, foregroundNotificationDelegate == null ? new Notification() : foregroundNotificationDelegate.getNotification());
39-
36+
if (foregroundNotificationDelegate == null) {
37+
startService(new Intent(this, InnerService.class));
38+
startForeground(NOTIFY_ID, new Notification());
39+
} else if (foregroundNotificationDelegate.isEnable()) {
40+
startForeground(NOTIFY_ID, foregroundNotificationDelegate.getNotification());
41+
if (foregroundNotificationDelegate.isTryToHide())
42+
startService(new Intent(this, InnerService.class));
43+
}
4044
}
4145

4246
@Override

0 commit comments

Comments
 (0)