| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.mojo.shell; | 5 package org.chromium.mojo.shell; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.UiModeManager; | |
| 9 import android.content.Context; | 8 import android.content.Context; |
| 10 import android.content.Intent; | 9 import android.content.Intent; |
| 11 import android.content.ServiceConnection; | 10 import android.content.ServiceConnection; |
| 12 import android.content.res.Configuration; | |
| 13 import android.net.Uri; | 11 import android.net.Uri; |
| 14 import android.os.Bundle; | 12 import android.os.Bundle; |
| 15 import android.view.WindowManager; | |
| 16 | 13 |
| 17 import java.util.ArrayDeque; | 14 import java.util.ArrayDeque; |
| 18 | 15 |
| 19 /** | 16 /** |
| 20 * Activity for managing the Mojo Shell. | 17 * Entry point for the Mojo Shell application. |
| 21 */ | 18 */ |
| 22 public class MojoShellActivity extends Activity implements ShellService.IShellBi
ndingActivity { | 19 public class MojoShellActivity extends Activity implements ShellService.IShellBi
ndingActivity { |
| 23 private static final String TAG = "MojoShellActivity"; | 20 private static final String TAG = "MojoShellActivity"; |
| 24 private ArrayDeque<Intent> mPendingIntents = new ArrayDeque<Intent>(); | 21 private ArrayDeque<Intent> mPendingIntents = new ArrayDeque<Intent>(); |
| 25 private ShellService mShellService; | 22 private ShellService mShellService; |
| 26 private ServiceConnection mShellServiceConnection; | 23 private ServiceConnection mShellServiceConnection; |
| 27 | 24 |
| 28 @Override | 25 @Override |
| 29 protected void onCreate(final Bundle savedInstanceState) { | 26 protected void onCreate(final Bundle savedInstanceState) { |
| 30 super.onCreate(savedInstanceState); | 27 super.onCreate(savedInstanceState); |
| 31 | 28 |
| 32 Intent serviceIntent = new Intent(this, ShellService.class); | 29 Intent serviceIntent = new Intent(this, ShellService.class); |
| 33 // Copy potential startup arguments. | 30 // Copy potential startup arguments. |
| 34 serviceIntent.putExtras(getIntent()); | 31 serviceIntent.putExtras(getIntent()); |
| 35 startService(serviceIntent); | 32 startService(serviceIntent); |
| 36 bindShellService(serviceIntent); | 33 |
| 34 mShellServiceConnection = new ShellService.ShellServiceConnection(this); |
| 35 bindService(serviceIntent, mShellServiceConnection, Context.BIND_AUTO_CR
EATE); |
| 37 | 36 |
| 38 onNewIntent(getIntent()); | 37 onNewIntent(getIntent()); |
| 39 | |
| 40 // TODO(tonyg): Watch activities go back to the home screen within a | |
| 41 // couple of seconds of detaching from adb. So for demonstration purpose
s, | |
| 42 // we just keep the screen on. Eventually we'll want a solution for | |
| 43 // allowing the screen to sleep without quitting the shell. | |
| 44 // TODO(etiennej): Verify the above is still true after the switch to a
Service model. | |
| 45 UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_S
ERVICE); | |
| 46 if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_WAT
CH) { | |
| 47 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 private void bindShellService(Intent serviceIntent) { | |
| 52 if (mShellServiceConnection == null) { | |
| 53 mShellServiceConnection = new ShellService.ShellServiceConnection(th
is); | |
| 54 bindService(serviceIntent, mShellServiceConnection, Context.BIND_AUT
O_CREATE); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 private void unbindShellService() { | |
| 59 if (mShellServiceConnection != null) { | |
| 60 unbindService(mShellServiceConnection); | |
| 61 mShellServiceConnection = null; | |
| 62 } | |
| 63 } | 38 } |
| 64 | 39 |
| 65 @Override | 40 @Override |
| 66 protected void onRestart() { | |
| 67 super.onRestart(); | |
| 68 bindShellService(new Intent(this, ShellService.class)); | |
| 69 } | |
| 70 | |
| 71 @Override | |
| 72 protected void onStop() { | |
| 73 super.onStop(); | |
| 74 unbindShellService(); | |
| 75 } | |
| 76 | |
| 77 @Override | |
| 78 protected void onNewIntent(Intent intent) { | 41 protected void onNewIntent(Intent intent) { |
| 79 super.onNewIntent(intent); | 42 super.onNewIntent(intent); |
| 80 setIntent(intent); | 43 setIntent(intent); |
| 81 mPendingIntents.add(intent); | 44 mPendingIntents.add(intent); |
| 82 | |
| 83 if (mShellService != null) { | |
| 84 communicateWithShell(); | |
| 85 } | |
| 86 } | 45 } |
| 87 | 46 |
| 88 @Override | 47 @Override |
| 89 public void onShellBound(ShellService shellService) { | 48 public void onShellBound(ShellService shellService) { |
| 90 mShellService = shellService; | 49 mShellService = shellService; |
| 50 finish(); |
| 91 communicateWithShell(); | 51 communicateWithShell(); |
| 52 unbindService(mShellServiceConnection); |
| 92 } | 53 } |
| 93 | 54 |
| 94 @Override | 55 @Override |
| 95 public void onShellUnbound() { | 56 public void onShellUnbound() { |
| 96 mShellService = null; | 57 mShellService = null; |
| 58 mShellServiceConnection = null; |
| 97 } | 59 } |
| 98 | 60 |
| 99 /** | 61 /** |
| 100 * Communicate with the shell to start new apps, based on pending intents. | 62 * Communicate with the shell to start new apps, based on pending intents. |
| 101 */ | 63 */ |
| 102 private void communicateWithShell() { | 64 private void communicateWithShell() { |
| 103 while (!mPendingIntents.isEmpty()) { | 65 while (!mPendingIntents.isEmpty()) { |
| 104 Intent intent = mPendingIntents.remove(); | 66 Intent intent = mPendingIntents.remove(); |
| 105 Uri data = intent.getData(); | 67 Uri data = intent.getData(); |
| 106 if (data != null) { | 68 if (data != null) { |
| 107 String url = data.buildUpon().scheme("https").build().toString()
; | 69 String url = data.buildUpon().scheme("https").build().toString()
; |
| 108 mShellService.startApplicationURL(url); | 70 mShellService.startApplicationURL(url); |
| 109 } | 71 } |
| 110 } | 72 } |
| 111 } | 73 } |
| 112 | 74 |
| 113 /** | 75 /** |
| 114 * @see Activity#onActivityResult(int, int, Intent) | 76 * @see Activity#onActivityResult(int, int, Intent) |
| 115 */ | 77 */ |
| 116 @Override | 78 @Override |
| 117 protected void onActivityResult(int requestCode, int resultCode, Intent data
) { | 79 protected void onActivityResult(int requestCode, int resultCode, Intent data
) { |
| 118 IntentReceiverRegistry.getInstance().onActivityResult(requestCode, resul
tCode, data); | 80 IntentReceiverRegistry.getInstance().onActivityResult(requestCode, resul
tCode, data); |
| 119 } | 81 } |
| 120 } | 82 } |
| OLD | NEW |