Commit 11b08c2b authored by Geoffrey Métais's avatar Geoffrey Métais

Use application context to call system services

parent c9325dc1
......@@ -181,7 +181,7 @@ public class AudioService extends Service {
// Make sure the audio player will acquire a wake-lock while playing. If we don't do
// that, the CPU might go to sleep while the song is playing, causing playback to stop.
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager pm = (PowerManager) VLCApplication.getAppContext().getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
IntentFilter filter = new IntentFilter();
......@@ -228,7 +228,7 @@ public class AudioService extends Service {
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void setUpRemoteControlClient() {
Context context = VLCApplication.getAppContext();
AudioManager audioManager = (AudioManager)context.getSystemService(AUDIO_SERVICE);
AudioManager audioManager = (AudioManager)VLCApplication.getAppContext().getSystemService(AUDIO_SERVICE);
if (LibVlcUtil.isICSOrLater()) {
audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
......@@ -350,7 +350,7 @@ public class AudioService extends Service {
};
}
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
AudioManager am = (AudioManager)VLCApplication.getAppContext().getSystemService(AUDIO_SERVICE);
if(gain)
am.requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
else
......@@ -386,7 +386,7 @@ public class AudioService extends Service {
}
// skip all headsets events if there is a call
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
TelephonyManager telManager = (TelephonyManager) VLCApplication.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
if (telManager != null && telManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)
return;
......
......@@ -129,7 +129,7 @@ public class DebugLogActivity extends Activity implements DebugLogService.Client
for (String line : mLogList)
buffer.append(line+"\n");
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)VLCApplication.getAppContext().getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(buffer);
Toast.makeText(DebugLogActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
......
......@@ -61,6 +61,7 @@ import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.audio.AudioService;
import org.videolan.vlc.gui.SidebarAdapter.SidebarEntry;
import org.videolan.vlc.gui.audio.AudioBrowserFragment;
......@@ -396,7 +397,7 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
if (LibVlcUtil.isFroyoOrLater()) {
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
(SearchManager) VLCApplication.getAppContext().getSystemService(Context.SEARCH_SERVICE);
mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.ml_menu_search));
mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
mSearchView.setQueryHint(getString(R.string.search_hint));
......@@ -716,7 +717,7 @@ public class MainActivity extends AudioPlayerContainerActivity implements OnItem
};
public void hideKeyboard(){
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
((InputMethodManager) VLCApplication.getAppContext().getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
getWindow().getDecorView().getRootView().getWindowToken(), 0);
}
......
......@@ -53,6 +53,7 @@ import android.widget.ViewSwitcher;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.audio.AudioServiceController;
import org.videolan.vlc.audio.RepeatType;
import org.videolan.vlc.gui.AudioPlayerContainerActivity;
......@@ -632,11 +633,8 @@ public class AudioPlayer extends Fragment implements IAudioPlayer, View.OnClickL
@Override
public void run() {
if(!vibrated) {
Activity activity = AudioPlayer.this.getActivity();
if (activity != null) {
((android.os.Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE))
((android.os.Vibrator) VLCApplication.getAppContext().getSystemService(Context.VIBRATOR_SERVICE))
.vibrate(80);
}
vibrated = true;
}
......
......@@ -313,7 +313,7 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
}
public static void setSleep(Context context, Calendar time) {
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AlarmManager alarmMgr = (AlarmManager) VLCApplication.getAppContext().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(VLCApplication.SLEEP_INTENT);
PendingIntent sleepPendingIntent = PendingIntent.getBroadcast(VLCApplication.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
......
......@@ -333,7 +333,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
if (LibVlcUtil.isJellyBeanMR1OrLater()) {
// Get the media router service (Miracast)
mMediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
mMediaRouter = (MediaRouter) VLCApplication.getAppContext().getSystemService(Context.MEDIA_ROUTER_SERVICE);
mMediaRouterCallback = new MediaRouter.SimpleCallback() {
@Override
public void onRoutePresentationDisplayChanged(
......@@ -351,7 +351,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
/* Services and miscellaneous */
mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
mAudioManager = (AudioManager) VLCApplication.getAppContext().getSystemService(AUDIO_SERVICE);
mAudioMax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
mEnableCloneMode = mSettings.getBoolean("enable_clone_mode", false);
......@@ -2638,7 +2638,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
* the background.
* To workaround this, pause playback if the lockscreen is displayed.
*/
final KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
final KeyguardManager km = (KeyguardManager) VLCApplication.getAppContext().getSystemService(KEYGUARD_SERVICE);
if (km.inKeyguardRestrictedInputMode())
wasPaused = true;
else
......@@ -2865,7 +2865,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
@SuppressWarnings("deprecation")
private int getScreenRotation(){
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
WindowManager wm = (WindowManager) VLCApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO /* Android 2.2 has getRotation */) {
try {
......@@ -2881,7 +2881,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private int getScreenOrientation(){
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
WindowManager wm = (WindowManager) VLCApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int rot = getScreenRotation();
/*
......
......@@ -52,7 +52,7 @@ public class BitmapCache {
// Get memory class of this device, exceeding this amount will throw an
// OutOfMemory exception.
final ActivityManager am = ((ActivityManager) context.getSystemService(
final ActivityManager am = ((ActivityManager) VLCApplication.getAppContext().getSystemService(
Context.ACTIVITY_SERVICE));
final int memClass = LibVlcUtil.isHoneycombOrLater() ? am.getLargeMemoryClass() : am.getMemoryClass();
......
......@@ -43,7 +43,7 @@ public class BootupReceiver extends BroadcastReceiver {
}
private void scheduleRecommendationUpdate(Context context) {
AlarmManager alarmManager = (AlarmManager)context.getSystemService(
AlarmManager alarmManager = (AlarmManager) VLCApplication.getAppContext().getSystemService(
Context.ALARM_SERVICE);
Intent recommendationIntent = new Intent(context,
RecommendationsService.class);
......
......@@ -427,7 +427,7 @@ public class MainTvActivity extends Activity implements IVideoBrowser, OnItemVie
return;
String action = intent.getAction();
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
final NetworkInfo networkInfo = ((ConnectivityManager)context.getSystemService(
final NetworkInfo networkInfo = ((ConnectivityManager) VLCApplication.getAppContext().getSystemService(
Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (networkInfo == null || networkInfo.getState() == NetworkInfo.State.CONNECTED) {
if (networkInfo == null){
......
......@@ -64,7 +64,7 @@ public class RecommendationsService extends IntentService {
mContext = this;
if (mNotificationManager == null) {
mNotificationManager = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
VLCApplication.getAppContext().getSystemService(Context.NOTIFICATION_SERVICE);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment