Skip to content

Commit 85e58ba

Browse files
Merge pull request #633 from TakayukiHoshi1984/modify_host_plugin_type_direct
HostプラグインのタイプをBinderからDirectに修正
2 parents 68fbfd8 + cf472a7 commit 85e58ba

22 files changed

Lines changed: 403 additions & 807 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Built application files
55
*.apk
66
*.ap_
7+
.externalNativeBuild
78

89
# Files for the Dalvik VM
910
*.dex

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,6 @@
130130
android:exported="true" >
131131

132132
</provider>
133-
<service
134-
android:name="org.deviceconnect.android.deviceplugin.host.HostDeviceService"
135-
android:exported="true">
136-
<meta-data
137-
android:name="org.deviceconnect.android.deviceplugin"
138-
android:resource="@xml/org_deviceconnect_android_deviceplugin_host"/>
139-
140-
<meta-data
141-
android:name="org.deviceconnect.android.deviceplugin.name"
142-
android:value="@string/app_name_host"/>
143-
144-
<meta-data
145-
android:name="org.deviceconnect.android.deviceplugin.icon"
146-
android:resource="@drawable/dconnect_icon"/>
147-
</service>
148133
</application>
149134

150135
</manifest>

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/HostDevicePlugin.java

Lines changed: 118 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
import android.content.pm.PackageManager;
1515
import android.net.wifi.WifiManager;
1616
import android.os.Bundle;
17+
import android.os.Handler;
18+
import android.os.Looper;
1719
import android.telephony.TelephonyManager;
18-
import android.util.Log;
1920

21+
import org.deviceconnect.android.deviceplugin.demo.DemoInstaller;
2022
import org.deviceconnect.android.deviceplugin.host.battery.HostBatteryManager;
2123
import org.deviceconnect.android.deviceplugin.host.camera.CameraWrapperManager;
24+
import org.deviceconnect.android.deviceplugin.host.demo.HostDemoInstaller;
2225
import org.deviceconnect.android.deviceplugin.host.file.FileDataManager;
2326
import org.deviceconnect.android.deviceplugin.host.file.HostFileProvider;
2427
import org.deviceconnect.android.deviceplugin.host.mediaplayer.HostMediaPlayerManager;
2528
import org.deviceconnect.android.deviceplugin.host.profile.HostBatteryProfile;
29+
import org.deviceconnect.android.deviceplugin.host.profile.HostCameraProfile;
2630
import org.deviceconnect.android.deviceplugin.host.profile.HostCanvasProfile;
2731
import org.deviceconnect.android.deviceplugin.host.profile.HostConnectionProfile;
2832
import org.deviceconnect.android.deviceplugin.host.profile.HostDeviceOrientationProfile;
@@ -39,10 +43,13 @@
3943
import org.deviceconnect.android.deviceplugin.host.profile.HostSystemProfile;
4044
import org.deviceconnect.android.deviceplugin.host.profile.HostTouchProfile;
4145
import org.deviceconnect.android.deviceplugin.host.profile.HostVibrationProfile;
46+
import org.deviceconnect.android.deviceplugin.host.recorder.AbstractPreviewServerProvider;
4247
import org.deviceconnect.android.deviceplugin.host.recorder.HostDevicePhotoRecorder;
4348
import org.deviceconnect.android.deviceplugin.host.recorder.HostDeviceRecorder;
4449
import org.deviceconnect.android.deviceplugin.host.recorder.HostDeviceRecorderManager;
50+
import org.deviceconnect.android.deviceplugin.host.recorder.PreviewServer;
4551
import org.deviceconnect.android.deviceplugin.host.recorder.PreviewServerProvider;
52+
import org.deviceconnect.android.deviceplugin.host.recorder.util.RecorderSettingData;
4653
import org.deviceconnect.android.event.Event;
4754
import org.deviceconnect.android.event.EventManager;
4855
import org.deviceconnect.android.message.DevicePluginContext;
@@ -52,9 +59,14 @@
5259
import org.deviceconnect.android.provider.FileManager;
5360
import org.deviceconnect.android.service.DConnectService;
5461

62+
import java.io.File;
63+
import java.io.IOException;
64+
import java.util.ArrayList;
5565
import java.util.List;
5666
import java.util.logging.Logger;
5767

68+
import static org.deviceconnect.android.deviceplugin.host.recorder.util.RecorderSettingData.PREVIEW_JPEG_MIME_TYPE;
69+
5870
/**
5971
* Host Device Plugin Context.
6072
*
@@ -88,11 +100,24 @@ public class HostDevicePlugin extends DevicePluginContext {
88100

89101
/** レコーダ管理クラス. */
90102
private HostDeviceRecorderManager mRecorderMgr;
103+
/**
104+
* MediaStreamRecordingProfile の実装.
105+
*/
106+
private HostMediaStreamingRecordingProfile mHostMediaStreamRecordingProfile;
91107

92108
/**
93109
* Phone プロファイルの実装.
94110
*/
95111
private HostPhoneProfile mPhoneProfile;
112+
/**
113+
* デモページインストーラ.
114+
*/
115+
private DemoInstaller mDemoInstaller;
116+
117+
/**
118+
* デモページアップデート通知.
119+
*/
120+
private DemoInstaller.Notification mDemoNotification;
96121

97122
/**
98123
* ブロードキャストレシーバー.
@@ -117,7 +142,20 @@ public void onReceive(final Context context, final Intent intent) {
117142
}
118143
}
119144
};
120-
145+
/**
146+
* デモページ関連の通知を受信するレシーバー.
147+
*/
148+
private final BroadcastReceiver mDemoNotificationReceiver = new BroadcastReceiver() {
149+
@Override
150+
public void onReceive(final Context context, final Intent intent) {
151+
String action = intent.getAction();
152+
mLogger.info("Demo Notification: " + action);
153+
mDemoNotification.cancel(context);
154+
if (DemoInstaller.Notification.ACTON_UPDATE_DEMO.equals(action)) {
155+
updateDemoPage(context);
156+
}
157+
}
158+
};
121159
/**
122160
* コンストラクタ.
123161
*
@@ -131,12 +169,21 @@ public HostDevicePlugin(Context context) {
131169

132170
mFileMgr = new FileManager(context, HostFileProvider.class.getName());
133171
mFileDataManager = new FileDataManager(mFileMgr);
134-
172+
mDemoInstaller = new HostDemoInstaller(getContext());
173+
mDemoNotification = new DemoInstaller.Notification(
174+
1,
175+
getContext().getString(R.string.app_name_host),
176+
R.drawable.dconnect_icon,
177+
"org.deviceconnect.android.deviceconnect.host.channel.demo",
178+
"Host Plugin Demo Page",
179+
"Host Plugin Demo Page"
180+
);
135181
mHostBatteryManager = new HostBatteryManager(this);
136182
mHostBatteryManager.getBatteryInfo();
137183
mRecorderMgr = new HostDeviceRecorderManager(this);
138184
initRecorders(mRecorderMgr);
139185
mRecorderMgr.start();
186+
initRecorderSetting(mRecorderMgr);
140187
mHostMediaPlayerManager = new HostMediaPlayerManager(this);
141188

142189
DConnectService hostService = new DConnectService(SERVICE_ID);
@@ -164,7 +211,9 @@ public HostDevicePlugin(Context context) {
164211
}
165212

166213
if (mRecorderMgr.getRecorders().length > 0) {
167-
hostService.addProfile(new HostMediaStreamingRecordingProfile(mRecorderMgr, mFileMgr));
214+
mHostMediaStreamRecordingProfile = new HostMediaStreamingRecordingProfile(mRecorderMgr, mFileMgr);
215+
hostService.addProfile(mHostMediaStreamRecordingProfile);
216+
hostService.addProfile(new HostCameraProfile(mRecorderMgr));
168217
}
169218
if (checkCameraHardware()) {
170219
HostDeviceRecorder defaultRecorder = mRecorderMgr.getRecorder(null);
@@ -189,8 +238,25 @@ public HostDevicePlugin(Context context) {
189238
filter.addAction(PreviewServerProvider.DELETE_PREVIEW_ACTION);
190239
getContext().registerReceiver(mHostConnectionReceiver, filter);
191240

241+
registerDemoNotification();
242+
updateDemoPageIfNeeded();
192243
}
193244

245+
private void registerDemoNotification() {
246+
IntentFilter filter = new IntentFilter();
247+
filter.addAction(DemoInstaller.Notification.ACTON_CONFIRM_NEW_DEMO);
248+
filter.addAction(DemoInstaller.Notification.ACTON_UPDATE_DEMO);
249+
getContext().registerReceiver(mDemoNotificationReceiver, filter);
250+
}
251+
private void updateDemoPageIfNeeded() {
252+
final Context context = getContext();
253+
if (DemoInstaller.isUpdateNeeded(context)) {
254+
mLogger.info("Demo page must be updated.");
255+
updateDemoPage(context);
256+
} else {
257+
mLogger.info("Demo page update is not needed.");
258+
}
259+
}
194260
private void initRecorders(final HostDeviceRecorderManager recorderMgr) {
195261
if (checkCameraHardware()) {
196262
mCameraWrapperManager = new CameraWrapperManager(getContext());
@@ -203,32 +269,64 @@ private void initRecorders(final HostDeviceRecorderManager recorderMgr) {
203269
recorderMgr.createScreenCastRecorder(mFileMgr);
204270
}
205271
}
272+
private void initRecorderSetting(final HostDeviceRecorderManager recorderMgr) {
273+
final RecorderSettingData setting = RecorderSettingData.getInstance(getContext().getApplicationContext());
274+
List<String> targets = new ArrayList<>();
275+
276+
for (HostDeviceRecorder recorder : recorderMgr.getRecorders()) {
277+
if (recorder instanceof AbstractPreviewServerProvider) {
278+
PreviewServer server = ((AbstractPreviewServerProvider) recorder).getServerForMimeType(PREVIEW_JPEG_MIME_TYPE);
279+
if (server != null) {
280+
targets.add(recorder.getId());
281+
setting.storePreviewQuality(recorder.getId(), server.getQuality());
282+
setting.storePreviewName(recorder.getId(), recorder.getName());
283+
}
284+
}
285+
}
286+
setting.saveTargets(targets.toArray(new String[targets.size()]));
287+
}
288+
private void updateDemoPage(final Context context) {
289+
mDemoInstaller.update(new DemoInstaller.UpdateCallback() {
290+
@Override
291+
public void onBeforeUpdate(final File demoDir) {
292+
mLogger.info("Updating demo page: " + demoDir.getAbsolutePath());
293+
}
294+
295+
@Override
296+
public void onAfterUpdate(final File demoDir) {
297+
mLogger.info("Updated demo page: " + demoDir.getAbsolutePath());
298+
mDemoNotification.showUpdateSuccess(context);
299+
}
300+
301+
@Override
302+
public void onFileError(final IOException e) {
303+
mLogger.severe("Failed to update demo page for file error: " + e.getMessage());
304+
mDemoNotification.showUpdateError(context);
305+
}
306+
307+
@Override
308+
public void onUnexpectedError(final Throwable e) {
309+
mLogger.severe("Failed to update demo page for unexpected error: " + e.getMessage());
310+
mDemoNotification.showUpdateError(context);
311+
}
312+
}, new Handler(Looper.getMainLooper()));
313+
}
206314

207315
@Override
208316
public void release() {
209317
mRecorderMgr.stop();
210318
mRecorderMgr.clean();
319+
mRecorderMgr.destroy();
211320
mFileDataManager.stopTimer();
212-
getContext().unregisterReceiver(mHostConnectionReceiver);
213321
if (mCameraWrapperManager != null) {
214322
mCameraWrapperManager.destroy();
215323
}
324+
if (mHostMediaStreamRecordingProfile != null) {
325+
mHostMediaStreamRecordingProfile.destroy();
326+
}
327+
getContext().unregisterReceiver(mHostConnectionReceiver);
328+
getContext().unregisterReceiver(mDemoNotificationReceiver);
216329
super.release();
217-
// unregisterReceiver(mHostConnectionReceiver);
218-
// super.onDestroy();
219-
// }
220-
//
221-
// @Override
222-
// public int onStartCommand(final Intent intent, final int flags, final int startId) {
223-
// if (intent == null) {
224-
// return START_STICKY;
225-
// }
226-
//
227-
// String action = intent.getAction();
228-
// if (PreviewServerProvider.DELETE_PREVIEW_ACTION.equals(action)) {
229-
// return stopWebServer(intent);
230-
// }
231-
// return super.onStartCommand(intent, flags, startId);
232330
}
233331

234332
// Managerアンインストール検知時の処理。
@@ -286,44 +384,11 @@ protected SystemProfile getSystemProfile() {
286384
public int getPluginXmlResId() {
287385
return R.xml.org_deviceconnect_android_deviceplugin_host;
288386
}
289-
/**
290-
* Get a instance of FileManager.
291-
*
292-
* @return FileManager
293-
*/
294-
public FileManager getFileManager() {
295-
return mFileMgr;
296-
}
297-
298-
/**
299-
* カメラ管理クラスを取得する.
300-
*
301-
* @return カメラ管理クラス. 端末がカメラを持たない場合は<code>null</code>
302-
*/
303-
public CameraWrapperManager getCameraManager() {
304-
return mCameraWrapperManager;
305-
}
306-
307-
/**
308-
* レコーダー管理クラスを取得する.
309-
*
310-
* @return レコーダー管理クラス
311-
*/
312-
public HostDeviceRecorderManager getRecorderManager() {
313-
return mRecorderMgr;
314-
}
315387

316388
private void stopWebServer(final Intent intent) {
317389
mRecorderMgr.stopWebServer(intent.getStringExtra(PreviewServerProvider.EXTRA_CAMERA_ID));
318390
}
319391

320-
// @Override
321-
// public void onConfigurationChanged(final Configuration newConfig) {
322-
// WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
323-
// int rotation = windowManager.getDefaultDisplay().getRotation();
324-
// mLogger.info("onConfigurationChanged: rotation=" + rotation);
325-
// }
326-
327392
private void onChangedBluetoothStatus() {
328393
List<Event> events = EventManager.INSTANCE.getEventList(SERVICE_ID, HostConnectionProfile.PROFILE_NAME, null,
329394
HostConnectionProfile.ATTRIBUTE_ON_BLUETOOTH_CHANGE);

0 commit comments

Comments
 (0)