Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(935)

Unified Diff: samples/github/android/GithubMock/app/src/main/java/com/google/dartino/githubmock/GithubMockServer.java

Issue 2035023003: Remove service-compiler related code. (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: samples/github/android/GithubMock/app/src/main/java/com/google/dartino/githubmock/GithubMockServer.java
diff --git a/samples/github/android/GithubMock/app/src/main/java/com/google/dartino/githubmock/GithubMockServer.java b/samples/github/android/GithubMock/app/src/main/java/com/google/dartino/githubmock/GithubMockServer.java
deleted file mode 100644
index 5e128afe58bdfe0ed4d9db81a24d9a3b84da65df..0000000000000000000000000000000000000000
--- a/samples/github/android/GithubMock/app/src/main/java/com/google/dartino/githubmock/GithubMockServer.java
+++ /dev/null
@@ -1,149 +0,0 @@
-// Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE.md file.
-
-package com.google.dartino.githubmock;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.util.Log;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import dartino.DartinoApi;
-import dartino.DartinoServiceApi;
-
-/**
- * Service running a mock github http server.
- */
-public class GithubMockServer extends Service {
-
- @Override
- public void onCreate() {
- super.onCreate();
- startThread();
- startDartino();
- }
-
- @Override
- public void onDestroy() {
- stopDartino();
- stopThread();
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- Message message = handler.obtainMessage();
- message.obj = intent;
- handler.sendMessage(message);
- return START_REDELIVER_INTENT;
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
-
- private final class MockHandler extends Handler {
- public MockHandler(Looper looper) {
- super(looper);
- }
-
- @Override
- public void handleMessage(Message message) {
- if (message.obj == null) return;
- final Intent intent = (Intent)message.obj;
- final String action = intent.getAction();
- if (ACTION_ENSURE_SERVER.equals(action)) {
- handleActionEnsureServer();
- }
- }
- }
-
- /**
- * Ensure that the github mock server is running and broadcast its port.
- */
- private void handleActionEnsureServer() {
- // Broadcast the server port.
- Intent statusIntent = new Intent(ACTION_BROADCAST_STATUS);
- statusIntent.setPackage(GITHUB_SAMPLE_PACKAGE);
- statusIntent.putExtra(STATUS_DATA, SERVER_PORT);
- sendBroadcast(statusIntent);
- }
-
- private void startThread() {
- HandlerThread thread = new HandlerThread("GithubMockServer");
- thread.start();
- looper = thread.getLooper();
- handler = new MockHandler(looper);
- }
-
- private void stopThread() {
- looper.quit();
- }
-
- private void startDartino() {
- System.loadLibrary("dartino");
- DartinoApi.Setup();
- DartinoServiceApi.Setup();
- DartinoApi.AddDefaultSharedLibrary("libdartino.so");
- DartinoApi.RegisterPrintInterceptor(new PrintInterceptor());
- try (InputStream stream = getResources().openRawResource(R.raw.snapshot)) {
- final int bufferSize = 256;
- byte[] buffer = new byte[bufferSize];
- final ByteArrayOutputStream bytes = new ByteArrayOutputStream(stream.available());
- int bytesRead;
- while ((bytesRead = stream.read(buffer, 0, bufferSize)) >= 0) {
- bytes.write(buffer, 0, bytesRead);
- }
- Thread dartThread = new Thread(new DartRunner(bytes.toByteArray()));
- dartThread.start();
- } catch (IOException e) {
- System.err.println("Failed to start Dart service from snapshot.");
- System.exit(1);
- }
- dartino.GithubMockServer.Setup();
- dartino.GithubMockServer.start(SERVER_PORT);
- }
-
- private void stopDartino() {
- dartino.GithubMockServer.stop();
- dartino.GithubMockServer.TearDown();
- DartinoServiceApi.TearDown();
- DartinoApi.TearDown();
- }
-
- private class PrintInterceptor extends DartinoApi.PrintInterceptor {
- @Override public void Out(String message) { Log.i(TAG, message); }
- @Override public void Error(String message) { Log.e(TAG, message); }
- private static final String TAG = "Dartino";
- }
-
- private static final String GITHUB_SAMPLE_PACKAGE =
- "com.google.dartino.githubsample";
-
- private static final String INTENT_PREFIX =
- "com.google.dartino.githubmock";
-
- private static final String ACTION_ENSURE_SERVER =
- INTENT_PREFIX + ".action.ensureServer";
-
- private static final String ACTION_BROADCAST_STATUS =
- INTENT_PREFIX + ".action.broadcastStatus";
-
- private static final String STATUS_DATA =
- INTENT_PREFIX + ".data.status";
-
- // TODO(zerny): Make the server port dynamically selected.
- private static final int SERVER_PORT = 8321;
-
- private volatile Looper looper;
- private volatile Handler handler;
-}

Powered by Google App Engine
This is Rietveld 408576698