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.chromecast.shell; | 5 package org.chromium.chromecast.shell; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.BroadcastReceiver; | 8 import android.content.BroadcastReceiver; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if (DEBUG) Log.d(TAG, "onStop, window focus = %d", hasWindowFocus()); | 164 if (DEBUG) Log.d(TAG, "onStop, window focus = %d", hasWindowFocus()); |
165 | 165 |
166 if (isStopping()) { | 166 if (isStopping()) { |
167 // As soon as the cast app is no longer in the foreground, we ought
to immediately tear | 167 // As soon as the cast app is no longer in the foreground, we ought
to immediately tear |
168 // everything down. | 168 // everything down. |
169 finishGracefully(); | 169 finishGracefully(); |
170 | 170 |
171 // On pre-M devices, the device should be "unmuted" at the end of a
Cast application | 171 // On pre-M devices, the device should be "unmuted" at the end of a
Cast application |
172 // session, signaled by the activity exiting. See b/19964892. | 172 // session, signaled by the activity exiting. See b/19964892. |
173 if (Build.VERSION.SDK_INT < 23) { | 173 if (Build.VERSION.SDK_INT < 23) { |
174 AudioManager audioManager = CastAudioManager.getAudioManager(thi
s); | 174 releaseStreamMuteIfNecessary(); |
175 boolean isMuted = false; | |
176 try { | |
177 isMuted = (Boolean) audioManager.getClass().getMethod("isStr
eamMute", int.class) | |
178 .invoke(audioManager, AudioManager.STREAM_MUSIC); | |
179 } catch (Exception e) { | |
180 Log.e(TAG, "Cannot call AudioManager.isStreamMute().", e); | |
181 } | |
182 | |
183 if (isMuted) { | |
184 // Note: this is a no-op on fixed-volume devices. | |
185 audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false)
; | |
186 } | |
187 } | 175 } |
188 } | 176 } |
189 | 177 |
190 super.onStop(); | 178 super.onStop(); |
191 } | 179 } |
192 | 180 |
193 @Override | 181 @Override |
194 protected void onResume() { | 182 protected void onResume() { |
195 if (DEBUG) Log.d(TAG, "onResume"); | 183 if (DEBUG) Log.d(TAG, "onResume"); |
196 super.onResume(); | 184 super.onResume(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 mReceivedUserLeave = true; | 217 mReceivedUserLeave = true; |
230 } | 218 } |
231 | 219 |
232 protected void finishGracefully() { | 220 protected void finishGracefully() { |
233 if (mNativeCastWindow != 0) { | 221 if (mNativeCastWindow != 0) { |
234 mCastWindowManager.stopCastWindow(mNativeCastWindow, true /* gracefu
lly */); | 222 mCastWindowManager.stopCastWindow(mNativeCastWindow, true /* gracefu
lly */); |
235 mNativeCastWindow = 0; | 223 mNativeCastWindow = 0; |
236 } | 224 } |
237 } | 225 } |
238 | 226 |
| 227 @SuppressWarnings("deprecation") |
| 228 private void releaseStreamMuteIfNecessary() { |
| 229 AudioManager audioManager = CastAudioManager.getAudioManager(this); |
| 230 boolean isMuted = false; |
| 231 try { |
| 232 isMuted = (Boolean) audioManager.getClass().getMethod("isStreamMute"
, int.class) |
| 233 .invoke(audioManager, AudioManager.STREAM_MUSIC); |
| 234 } catch (Exception e) { |
| 235 Log.e(TAG, "Cannot call AudioManager.isStreamMute().", e); |
| 236 } |
| 237 |
| 238 if (isMuted) { |
| 239 // Note: this is a no-op on fixed-volume devices. |
| 240 audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false); |
| 241 } |
| 242 } |
| 243 |
239 private void registerBroadcastReceiver() { | 244 private void registerBroadcastReceiver() { |
240 if (mBroadcastReceiver == null) { | 245 if (mBroadcastReceiver == null) { |
241 mBroadcastReceiver = new BroadcastReceiver() { | 246 mBroadcastReceiver = new BroadcastReceiver() { |
242 @Override | 247 @Override |
243 public void onReceive(Context context, Intent intent) { | 248 public void onReceive(Context context, Intent intent) { |
244 Log.d(TAG, "Received intent: action=%s", intent.getAction())
; | 249 Log.d(TAG, "Received intent: action=%s", intent.getAction())
; |
245 if (CastWindowAndroid.ACTION_ENABLE_DEV_TOOLS.equals(intent.
getAction())) { | 250 if (CastWindowAndroid.ACTION_ENABLE_DEV_TOOLS.equals(intent.
getAction())) { |
246 mCastWindowManager.nativeEnableDevTools(true); | 251 mCastWindowManager.nativeEnableDevTools(true); |
247 } else if (CastWindowAndroid.ACTION_DISABLE_DEV_TOOLS.equals
( | 252 } else if (CastWindowAndroid.ACTION_DISABLE_DEV_TOOLS.equals
( |
248 intent.getAction())) { | 253 intent.getAction())) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 @Override | 329 @Override |
325 public boolean dispatchTouchEvent(MotionEvent ev) { | 330 public boolean dispatchTouchEvent(MotionEvent ev) { |
326 return false; | 331 return false; |
327 } | 332 } |
328 | 333 |
329 @Override | 334 @Override |
330 public boolean dispatchTrackballEvent(MotionEvent ev) { | 335 public boolean dispatchTrackballEvent(MotionEvent ev) { |
331 return false; | 336 return false; |
332 } | 337 } |
333 } | 338 } |
OLD | NEW |