Skip to content

Commit 270eb44

Browse files
committed
优化AIDL启动负一屏代码
1 parent 793c648 commit 270eb44

20 files changed

+314
-652
lines changed

effectivecard/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<service
66
android:name="com.codemx.effectivecard.CardService"
77
android:enabled="true"
8-
android:exported="true">
8+
android:exported="true"
9+
android:process="com.codemx.effectivecard">
910
<intent-filter>
1011
<action android:name="com.codemx.launcher3.WINDOW_OVERLAY" />
1112
</intent-filter>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ILauncherOverlay.aidl
2+
package com.codemx.effectivecard.launcherclient;
3+
4+
// Declare any non-default types here with import statements
5+
6+
import com.codemx.effectivecard.launcherclient.MxLayoutParams;
7+
import com.codemx.effectivecard.launcherclient.ILauncherOverlayCallback;
8+
9+
interface ILauncherOverlay {
10+
11+
void startScroll();
12+
13+
void onScroll(float progress, boolean isRtl) ;
14+
15+
void endScroll() ;
16+
17+
void windowAttached(in MxLayoutParams layoutParams, ILauncherOverlayCallback overlayCallback, int flags) ;
18+
19+
void windowDetached(boolean isChangingConfigurations) ;
20+
21+
void closeOverlay(int flags) ;
22+
23+
void onPause() ;
24+
25+
void onResume() ;
26+
27+
void openOverlay(int flags) ;
28+
29+
void requestVoiceDetection(boolean start) ;
30+
31+
String getVoiceSearchLanguage() ;
32+
33+
boolean isVoiceDetectionRunning() ;
34+
35+
void enableScroll(boolean left, boolean right) ;
36+
37+
void enableTransparentWallpaper(boolean isTransparent) ;
38+
39+
void enableLoopWithOverlay(boolean enableLoop) ;
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ILauncherOverlayCallback.aidl
2+
package com.codemx.effectivecard.launcherclient;
3+
4+
// Declare any non-default types here with import statements
5+
// 负一屏返回给Launcher的回调函数
6+
7+
interface ILauncherOverlayCallback {
8+
9+
// 负一屏滑动时通知桌面
10+
void overlayScrollChanged(float progress);
11+
12+
// 负一屏状态回调
13+
void overlayStatusChanged(int overlayAttached);
14+
15+
// 状态栏回调,需要Launcher去处理
16+
void requestStatusBarState(int state);
17+
18+
// 请求调用搜索栏
19+
void requestSearchActivity();
20+
21+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// LayoutParams.aidl
2+
package com.codemx.effectivecard.launcherclient;
3+
4+
parcelable MxLayoutParams;

effectivecard/src/main/java/com/codemx/effectivecard/CardService.java

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import android.content.Intent;
55
import android.os.IBinder;
66
import android.os.RemoteException;
7-
import android.view.WindowManager;
87

8+
import com.android.mxlibrary.util.XLog;
99
import com.codemx.effectivecard.launcherclient.ILauncherOverlay;
1010
import com.codemx.effectivecard.launcherclient.ILauncherOverlayCallback;
11+
import com.codemx.effectivecard.launcherclient.MxLayoutParams;
12+
13+
import java.lang.ref.WeakReference;
1114

1215
/**
1316
* Created by yuchuan
@@ -17,64 +20,98 @@
1720
public class CardService extends Service {
1821

1922
private ILauncherOverlay.Stub mStub;
20-
private ILauncherOverlayCallback mCallback;
23+
// 向Launcher通信的回调函数,对应LauncherOverlayCallbacks
24+
private ILauncherOverlayCallback mOverlayCallback;
2125

2226
@Override
2327
public void onCreate() {
2428
super.onCreate();
25-
mStub = new CardBinder();
29+
XLog.d(XLog.getTag(), "onCreate");
30+
mStub = new CardBinder(this);
2631
}
2732

2833
@Override
2934
public IBinder onBind(Intent intent) {
3035
return mStub;
3136
}
3237

38+
@Override
39+
public int onStartCommand(Intent intent, int flags, int startId) {
40+
XLog.d(XLog.getTag(), "onStartCommand");
41+
return super.onStartCommand(intent, flags, startId);
42+
}
43+
44+
@Override
45+
public boolean onUnbind(Intent intent) {
46+
XLog.d(XLog.getTag(), "onUnbind");
47+
return super.onUnbind(intent);
48+
}
49+
50+
@Override
51+
public void onDestroy() {
52+
super.onDestroy();
53+
XLog.d(XLog.getTag(), "onDestroy");
54+
}
55+
3356
// Launcher通过服务会调用这里的函数来达到与launcher同步,然后控制window滑动
3457
private static class CardBinder extends ILauncherOverlay.Stub {
58+
private WeakReference<CardService> mWeakReference;
59+
60+
CardBinder(CardService service) {
61+
mWeakReference = new WeakReference<>(service);
62+
}
3563

3664
@Override
3765
public void startScroll() throws RemoteException {
66+
XLog.d(XLog.getTag(), "startScroll");
3867
}
3968

4069
@Override
41-
public void onScroll(float progress) throws RemoteException {
70+
public void onScroll(float progress, boolean isRtl) throws RemoteException {
71+
XLog.d(XLog.getTag(), "startScroll#progress= " + progress + " ,isRtl= " + isRtl);
4272
}
4373

4474
@Override
4575
public void endScroll() throws RemoteException {
76+
XLog.d(XLog.getTag(), "endScroll");
4677
}
4778

4879
@Override
49-
public void windowAttached(WindowManager.LayoutParams layoutParams,
50-
ILauncherOverlayCallback overlayCallback, int flags) throws RemoteException {
51-
80+
public void windowAttached(MxLayoutParams layoutParams, ILauncherOverlayCallback overlayCallback, int flags) throws RemoteException {
81+
XLog.d(XLog.getTag(), "windowAttached " + layoutParams);
82+
if (mWeakReference != null && mWeakReference.get() != null) {
83+
mWeakReference.get().registerCallback(overlayCallback);
84+
}
5285
}
5386

5487
@Override
5588
public void windowDetached(boolean isChangingConfigurations) throws RemoteException {
89+
XLog.d(XLog.getTag(), "windowDetached " + isChangingConfigurations);
5690
}
5791

5892
@Override
5993
public void closeOverlay(int flags) throws RemoteException {
60-
94+
XLog.d(XLog.getTag(), "closeOverlay " + flags);
6195
}
6296

6397
@Override
6498
public void onPause() throws RemoteException {
99+
XLog.d(XLog.getTag(), "onPause ");
65100
}
66101

67102
@Override
68103
public void onResume() throws RemoteException {
104+
XLog.d(XLog.getTag(), "onResume ");
69105
}
70106

71107
@Override
72108
public void openOverlay(int flags) throws RemoteException {
109+
XLog.d(XLog.getTag(), "openOverlay " + flags);
73110
}
74111

75112
@Override
76113
public void requestVoiceDetection(boolean start) throws RemoteException {
77-
114+
XLog.d(XLog.getTag(), "requestVoiceDetection " + start);
78115
}
79116

80117
@Override
@@ -89,7 +126,7 @@ public boolean isVoiceDetectionRunning() throws RemoteException {
89126

90127
@Override
91128
public void enableScroll(boolean left, boolean right) throws RemoteException {
92-
129+
XLog.d(XLog.getTag(), "enableScroll left: " + left + " ,right: " + right);
93130
}
94131

95132
@Override
@@ -103,4 +140,8 @@ public void enableLoopWithOverlay(boolean enableLoop) throws RemoteException {
103140
}
104141
}
105142

143+
private void registerCallback(ILauncherOverlayCallback overlayCallback) {
144+
this.mOverlayCallback = overlayCallback;
145+
}
146+
106147
}

effectivecard/src/main/java/com/codemx/effectivecard/launcherclient/Constant.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ public final class Constant {
1010
public static final String GSA_PACKAGE = "com.codemx.effectcard";// 负一屏包名
1111
public static final String ACTION = "com.codemx.launcher3.WINDOW_OVERLAY";
1212

13+
private static final String DESCRIPTOR = "com.google.android.libraries.launcherclient.ILauncherOverlayCallback";
14+
static final int TRANSACTION_overlayScrollChanged = 1;
15+
static final int TRANSACTION_overlayStatusChanged = 2;
16+
static final int TRANSACTION_requestStatusbarState = 3;
17+
static final int TRANSACTION_requestSearchActivity = 4;
18+
1319

1420
}

0 commit comments

Comments
 (0)