OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.chromoting; | 5 package org.chromium.chromoting; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.ActivityNotFoundException; | 9 import android.content.ActivityNotFoundException; |
10 import android.content.ComponentName; | 10 import android.content.ComponentName; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.content.pm.PackageManager; | 12 import android.content.pm.PackageManager; |
13 import android.net.Uri; | 13 import android.net.Uri; |
14 import android.support.v7.app.ActionBarActivity; | |
15 import android.text.TextUtils; | 14 import android.text.TextUtils; |
16 import android.util.Base64; | 15 import android.util.Base64; |
17 import android.util.Log; | 16 import android.util.Log; |
18 | 17 |
19 import org.chromium.base.SecureRandomInitializer; | 18 import org.chromium.base.SecureRandomInitializer; |
20 | 19 |
21 import java.io.IOException; | 20 import java.io.IOException; |
22 import java.security.SecureRandom; | 21 import java.security.SecureRandom; |
23 import java.util.ArrayList; | 22 import java.util.ArrayList; |
24 | 23 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 * | 208 * |
210 * Unfortunately, most browsers on Android, e.g. chrome, reload the URL when
a browser | 209 * Unfortunately, most browsers on Android, e.g. chrome, reload the URL when
a browser |
211 * tab is activated. As a result, chromoting is launched unintentionally wh
en the user restarts | 210 * tab is activated. As a result, chromoting is launched unintentionally wh
en the user restarts |
212 * chrome or closes other tabs that causes the redirect URL to become the to
pmost tab. | 211 * chrome or closes other tabs that causes the redirect URL to become the to
pmost tab. |
213 * | 212 * |
214 * To solve the problem, the redirect intent-filter is declared in a separat
e activity, | 213 * To solve the problem, the redirect intent-filter is declared in a separat
e activity, |
215 * |OAuthRedirectActivity| instead of the MainActivity. In this way, we can
disable it, | 214 * |OAuthRedirectActivity| instead of the MainActivity. In this way, we can
disable it, |
216 * together with its intent filter, by default. |OAuthRedirectActivity| is o
nly enabled when | 215 * together with its intent filter, by default. |OAuthRedirectActivity| is o
nly enabled when |
217 * there is a pending token fetch request. | 216 * there is a pending token fetch request. |
218 */ | 217 */ |
219 public static class OAuthRedirectActivity extends ActionBarActivity { | 218 public static class OAuthRedirectActivity extends Activity { |
220 @Override | 219 @Override |
221 public void onStart() { | 220 public void onStart() { |
222 super.onStart(); | 221 super.onStart(); |
223 // |OAuthRedirectActivity| runs in its own task, it needs to route t
he intent back | 222 // |OAuthRedirectActivity| runs in its own task, it needs to route t
he intent back |
224 // to Chromoting.java to access the state of the current request. | 223 // to Chromoting.java to access the state of the current request. |
225 Intent intent = getIntent(); | 224 Intent intent = getIntent(); |
226 intent.setClass(this, Chromoting.class); | 225 intent.setClass(this, Chromoting.class); |
227 startActivity(intent); | 226 startActivity(intent); |
228 finishActivity(0); | 227 finishActivity(0); |
229 } | 228 } |
230 | 229 |
231 public static void setEnabled(Activity context, boolean enabled) { | 230 public static void setEnabled(Activity context, boolean enabled) { |
232 int enabledState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_
ENABLED | 231 int enabledState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_
ENABLED |
233 : PackageManager.COMPONENT_ENABLED_STATE_
DEFAULT; | 232 : PackageManager.COMPONENT_ENABLED_STATE_
DEFAULT; |
234 ComponentName component = new ComponentName( | 233 ComponentName component = new ComponentName( |
235 context.getApplicationContext(), | 234 context.getApplicationContext(), |
236 ThirdPartyTokenFetcher.OAuthRedirectActivity.class); | 235 ThirdPartyTokenFetcher.OAuthRedirectActivity.class); |
237 context.getPackageManager().setComponentEnabledSetting( | 236 context.getPackageManager().setComponentEnabledSetting( |
238 component, | 237 component, |
239 enabledState, | 238 enabledState, |
240 PackageManager.DONT_KILL_APP); | 239 PackageManager.DONT_KILL_APP); |
241 } | 240 } |
242 } | 241 } |
243 } | 242 } |
OLD | NEW |